V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · 3471 views
    This topic created in 4319 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   ·   Solana   ·   5650 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 06:51 · PVG 14:51 · LAX 23:51 · JFK 02:51
    ♥ Do have faith in what you're doing.