Django 新应用程序在开发中工作但不在生产中(Apache 服务器)

Django new application working in dev but not in production (Apache server)

我有一个在生产和开发中正常工作的 django 网站,最近我下载了 django-tables2 并使用它在本地服务器上进行开发没有问题。

然而,当把它放在我的生产服务器上时,它在转到 url.

时给我错误 500

我通过 sudo pip install django-tables2

安装了它

这是 apache 的错误日志:

[Tue Nov 27 10:32:39.633848 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400] mod_wsgi (pid=27589): Target WSGI script '/home/ubuntu/coding-platform/coding_platform/wsgi.py' cannot be loaded as Python module.
[Tue Nov 27 10:32:39.633932 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400] mod_wsgi (pid=27589): Exception occurred processing WSGI script '/home/ubuntu/coding-platform/coding_platform/wsgi.py'.
[Tue Nov 27 10:32:39.637556 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400] Traceback (most recent call last):
[Tue Nov 27 10:32:39.637611 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "/home/ubuntu/coding-platform/coding_platform/wsgi.py", line 19, in <module>
[Tue Nov 27 10:32:39.637618 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]     application = get_wsgi_application()
[Tue Nov 27 10:32:39.637627 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "/home/ubuntu/coding-platform/ENV/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Nov 27 10:32:39.637631 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]     django.setup(set_prefix=False)
[Tue Nov 27 10:32:39.637639 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "/home/ubuntu/coding-platform/ENV/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
[Tue Nov 27 10:32:39.637643 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]     apps.populate(settings.INSTALLED_APPS)
[Tue Nov 27 10:32:39.637650 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "/home/ubuntu/coding-platform/ENV/lib/python3.6/site-packages/django/apps/registry.py", line 89, in populate
[Tue Nov 27 10:32:39.637655 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]     app_config = AppConfig.create(entry)
[Tue Nov 27 10:32:39.637661 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "/home/ubuntu/coding-platform/ENV/lib/python3.6/site-packages/django/apps/config.py", line 90, in create
[Tue Nov 27 10:32:39.637674 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]     module = import_module(entry)
[Tue Nov 27 10:32:39.637682 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "/home/ubuntu/coding-platform/ENV/lib/python3.6/importlib/__init__.py", line 126, in import_module
[Tue Nov 27 10:32:39.637686 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]     return _bootstrap._gcd_import(name[level:], package, level)
[Tue Nov 27 10:32:39.637692 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Tue Nov 27 10:32:39.637699 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Tue Nov 27 10:32:39.637705 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400]   File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Tue Nov 27 10:32:39.637725 2018] [wsgi:error] [pid 27589:tid 139662681429760] [remote 213.152.28.84:63400] ModuleNotFoundError: No module named 'django_tables2'
[Tue Nov 27 10:32:39.879245 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397] mod_wsgi (pid=27589): Target WSGI script '/home/ubuntu/coding-platform/coding_platform/wsgi.py' cannot be loaded as Python module.
[Tue Nov 27 10:32:39.879301 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397] mod_wsgi (pid=27589): Exception occurred processing WSGI script '/home/ubuntu/coding-platform/coding_platform/wsgi.py'.
[Tue Nov 27 10:32:39.879439 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397] Traceback (most recent call last):
[Tue Nov 27 10:32:39.879479 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397]   File "/home/ubuntu/coding-platform/coding_platform/wsgi.py", line 19, in <module>
[Tue Nov 27 10:32:39.879485 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397]     application = get_wsgi_application()
[Tue Nov 27 10:32:39.879492 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397]   File "/home/ubuntu/coding-platform/ENV/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[Tue Nov 27 10:32:39.879497 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397]     django.setup(set_prefix=False)
[Tue Nov 27 10:32:39.879503 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397]   File "/home/ubuntu/coding-platform/ENV/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
[Tue Nov 27 10:32:39.879507 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397]     apps.populate(settings.INSTALLED_APPS)
[Tue Nov 27 10:32:39.879514 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397]   File "/home/ubuntu/coding-platform/ENV/lib/python3.6/site-packages/django/apps/registry.py", line 81, in populate
[Tue Nov 27 10:32:39.879518 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397]     raise RuntimeError("populate() isn't reentrant")
[Tue Nov 27 10:32:39.879535 2018] [wsgi:error] [pid 27589:tid 139662563825408] [remote 213.152.28.84:41397] RuntimeError: populate() isn't reentrant

这是我的 INSTALLED_APPS

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'coding',
    'django_tables2',
]

wsgi.py

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coding_platform.settings')

application = get_wsgi_application()

问题似乎来自wsgi.py,但我从未修改过这个文件,我做了很多研究但没有发现问题所在,我的猜测是生产需要额外的步骤下载额外的 django 包时,但在我读到的任何地方都没有提到它。

回溯中的关键行是:

ModuleNotFoundError: No module named 'django_tables2'

您的新软件包未安装在您的生产 virtualenv 中。祝你好运!