Skip to main content
 首页 » 编程设计

python之使用 CherryPy 服务 Django 1.7 应用程序

2024年08月26日28sharpest

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

调用后立即定义设置模块。