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

时间:2018-11-27 12:38:06

标签: python django apache mod-wsgi wsgi

我有一个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时,还需要执行更多生产步骤包装,但我伤心的地方都没提到。

1 个答案:

答案 0 :(得分:0)

回溯中的关键是:

ModuleNotFoundError: No module named 'django_tables2'

您的新软件包未安装在生产虚拟环境中。祝你好运!