我的任务是在Django中从1.5迁移到2.1。我目前在我的环境中使用Python 3.6.2。追溯如下:
(my_env) My-MBP:mysite my_mbp$ python manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10d82b598>
Traceback (most recent call last):
File "/Users/my_mbp/Software/Environments/my_env/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Users/my_mbp/Software/Environments/my_env/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 109, in inner_run
autoreload.raise_last_exception()
File "/Users/my_mbp/Software/Environments/my_env/lib/python3.6/site-packages/django/utils/autoreload.py", line 248, in raise_last_exception
raise _exception[1]
File "/Users/my_mbp/Software/Environments/my_env/lib/python3.6/site-packages/django/core/management/__init__.py", line 337, in execute
autoreload.check_errors(django.setup)()
File "/Users/my_mbp/Software/Environments/my_env/lib/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/Users/my_mbp/Software/Environments/my_env/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/my_mbp/Software/Environments/my_env/lib/python3.6/site-packages/django/apps/registry.py", line 81, in populate
raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant
由于回溯似乎是指站点程序包,因此我难以识别导致错误的代码中的内容。通过阅读其他文章,它似乎与wsgi有关,但我不知道确切是什么。这是我当前的wsgi设置:
import os
import sys
import site
## Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/Users/my_mbp/Software/Environments/my_env/lib/python3.6/site-packages')
## Add the app's directory to the PYTHONPATH
sys.path.append('/Users/my_mbp/Software/project/mysite')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
## Activate your virtual env
activate_env=os.path.expanduser("/Users/my_mbp/Software/Environments/my_env/bin/activate_this.py")
#execfile(activate_env, dict(__file__=activate_env))
with open(activate_env) as f:
code = compile(f.read(), activate_env, 'exec')
#exec(code, global_vars, local_vars)
exec(code)
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
要添加的另一件事是,当我在INSTALLED_APPS中将应用程序注释掉时,这会产生另一条错误消息:
RuntimeError: Model class myapp.models.Mail doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.