推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
yueyoum
V2EX  ›  Python

Django + uWSGI, 如何运行 startup 代码

  •  
  •   yueyoum ·
    yueyoum · Jun 30, 2014 · 3755 views
    This topic created in 4470 days ago, the information mentioned may be changed or developed.
    也就是用 uwsgi 将django 跑起来后, 首先让 startup code 执行。

    比如一个初始化函数,这个初始化函数又需要django.conf.settings 的配置,
    所以直接放在 settings.py 不行,

    其他地方也试过了, 貌似 python manage.py runserver 可以让startup code execute
    但是 用uwsgi跑django 就不行

    何解?
    3 replies  •  2014-06-30 17:35:43 +08:00
    yueyoum
        1
    yueyoum  
    OP
       Jun 30, 2014
    是我自己 uwsgi 配置的问题

    这个配置用了 两三年了
    module = django.core.handlers.wsgi:WSGIHandler()

    后来按照 django docs 改成

    module=mysite.wsgi:application

    就好了
    tf2
        2
    tf2  
       Jun 30, 2014
    uwsgi 配置里写 exec-pre-app 或者 import 都可以。
    yueyoum
        3
    yueyoum  
    OP
       Jun 30, 2014
    然后把 startup code 写到 mysite/wsgi.py 中就好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2563 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:47 · PVG 20:47 · LAX 05:47 · JFK 08:47
    ♥ Do have faith in what you're doing.