python - 使用 CherryPy 为 Django 1.7 应用程序提供服务

标签 python django cherrypy

我正在尝试使用 CherryPy 提供 Django 1.7 应用程序。启动脚本如下:

import wsgiserver
import sys
import os
import django.core.handlers.wsgi


if __name__ == "__main__":
    sys.path.append(os.path.realpath(os.path.dirname(__file__)))  # add django project absolute path
    # Startup Django
    os.environ['DJANGO_SETTINGS_MODULE'] = 'my_project.settings'
    server = wsgiserver.CherryPyWSGIServer(('127.0.0.1', 8001), django.core.handlers.wsgi.WSGIHandler())
try:
    server.start()
except KeyboardInterrupt:
    print 'Stopping'
    server.stop()

一切都设置好了。但是,当我尝试访问应用程序(django 成功页面)时,出现错误:

AppRegistryNotReady: The translation infrastructure cannot be initialized before the apps registry is ready. Check that you don't make non-lazy gettext calls at import time.

仔细阅读,我发现您在 runserver 之前运行迁移,并将 django.setup() 添加到 wsgi.py。遗憾的是,该解决方案对我不起作用。

我做错了什么?

提前谢谢您。

最佳答案

我不知道这是否是正确的解决方案,但我能够通过插入在我自己的代码中解决这个问题

django.setup()

在调用定义设置模块之后立即进行。

关于python - 使用 CherryPy 为 Django 1.7 应用程序提供服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26966788/

相关文章:

python - ValueError at/image/Tensor Tensor ("activation_5/Softmax:0", shape=(?, 4), dtype=float32) 不是这个图的元素

python - 使用 nginx 和 Python 防止网站在更新期间关闭

python - pip 在错误的 python 版本下安装 python 库

python - 我应该使用 "from package import utils, settings"还是 "from . import utils, settings"

python - Python2.7如何安装Six模块

python - matplotlib无法绘制彩色希尔伯特曲线?

每分钟运行不停的Python脚本

python - 访问 gunicorn 支持的服务时静默超时。如何调试?

python - CherryPy:为一个处理程序关闭工具

python - MultiIndex DataFrame 中基于现有列级别值的新级别