简体   繁体   中英

Serving Django 1.7 application using CherryPy

I'm trying to serve a Django 1.7 application using CherryPy. The startup script is as follows:

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()

Everything is setup okay. However, when i try accessing the application(the django success page) I get an error:

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.

Reading around, I found that you run the migrations before runserver and also add django.setup() to wsgi.py. Sadly that solution does not work for me.

What I'm I doing wrong?

Thank you in advance.

I don't know if this is the correct solution, but I was able to resolve this problem in my own code by inserting

django.setup()

immediately after the call to define the settings module.

在wsgiserver2.py中导入后,通过运行django.setup()使它起作用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM