推荐学习书目
› 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
yezheyu
V2EX  ›  Python

关于 django 项目中 wsgi 文件的一点小疑问,有老哥能帮忙解答下吗?

  •  
  •   yezheyu · Mar 21, 2021 · 2969 views
    This topic created in 2028 days ago, the information mentioned may be changed or developed.

    django 中 wsgi.py 文件有什么作用?

    是替代 manage.py 的一个启动 uwsgi 服务器的项目入口文件吗? 但我看安装好 uwsgi 后,新建个 uwsgi.ini 配置文件,然后使用 uwsgi --ini uwsgi.ini 就可以启动了,而不是用 python wsgi.py 后面跟上类似 runserver 这样的参数启动。

    最关键的是根本就没用到 wsgi.py 文件? 是因为在同一个目录下 uwsgi --ini uwsgi.ini 命令后省略了 -wsgi-file wsgi.py 参数吗? uwsgi 内部会帮我用 Python 启动项目吗?

    新手,见笑了

    4 replies  •  2021-03-21 22:16:41 +08:00
    yufpga
        1
    yufpga  
       Mar 21, 2021
    你看一下 uwsg.ini 文件是如何配置的, 其中有 chdir, module 等配置项, 用来指定 wsgi.py 的位置和目标 application, wsgi.py 中有一个 get_wsgi_application 函数调用,就是用来初始化目标 application, 有加载 django 的 settings 文件, 初始化一些 django 配置信息,具体等你熟悉以后翻一下源码就知道了
    izoabr
        2
    izoabr  
       Mar 21, 2021
    我用 gunicron 起应用就会用到这个文件
    对了,现在新的有 asgi.py 了
    Kobayashi
        3
    Kobayashi  
       Mar 21, 2021 via Android
    wsgi.app 定义了一个 WSGI app 实例,以便配合 WSGI server 启动。详情请自行搜索 WSGI 。
    julyclyde
        4
    julyclyde  
       Mar 21, 2021
    manage.py 是 django 调用 web 服务器来运行
    wsgi.py 是 django 被 web 服务器调用来运行

    你看一下 gunicorn 的 django 相关说明就知道了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3291 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 11:44 · PVG 19:44 · LAX 04:44 · JFK 07:44
    ♥ Do have faith in what you're doing.