我正在尝试使用 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/