V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2014-06-30 17:12:07 +08:00 · 3006 次点击
    这是一个创建于 3605 天前的主题,其中的信息可能已经有所发展或是发生改变。
    也就是用 uwsgi 将django 跑起来后, 首先让 startup code 执行。

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

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

    何解?
    3 条回复    2014-06-30 17:35:43 +08:00
    yueyoum
        1
    yueyoum  
    OP
       2014-06-30 17:23:26 +08:00
    是我自己 uwsgi 配置的问题

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

    后来按照 django docs 改成

    module=mysite.wsgi:application

    就好了
    lambdaq
        2
    lambdaq  
       2014-06-30 17:34:28 +08:00
    uwsgi 配置里写 exec-pre-app 或者 import 都可以。
    yueyoum
        3
    yueyoum  
    OP
       2014-06-30 17:35:43 +08:00
    然后把 startup code 写到 mysite/wsgi.py 中就好了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4016 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 10:30 · PVG 18:30 · LAX 03:30 · JFK 06:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.