gpt4 book ai didi

django - 关于 wsgi.py 中 wsgi 模块的 Ubuntu 16.04 服务器错误

转载 作者:行者123 更新时间:2023-12-04 18:55:59 27 4
gpt4 key购买 nike

我将在虚拟主机的 ubuntu 服务器上设置一个 django 应用程序。
我已经配置了我的虚拟主机,所以出现了一些问题!
但是由于您在此处看到的一些问题,它仍然给我 500 内部错误:

mod_wsgi (pid=31972): Target WSGI script '/var/www/mmcba/mmemp/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=31972): Exception occurred processing WSGI script '/var/www/mmcba/mmemp/wsgi.py'.
Traceback (most recent call last):
File "/var/www/mmcba/mmemp/wsgi.py", line 25, in <module>
application = django.core.handlers.wsgi.WSGIHandler()
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/wsgi.py", line 151, in __init__
self.load_middleware()
File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 80, in load_middleware
middleware = import_string(middleware_path)
File "/usr/local/lib/python3.5/dist-packages/django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/middleware.py", line 4, in <module>
from django.contrib.auth.backends import RemoteUserBackend
File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/backends.py", line 4, in <module>
from django.contrib.auth.models import Permission
File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/usr/local/lib/python3.5/dist-packages/django/db/models/base.py", line 110, in __new__
app_config = apps.get_containing_app_config(module)
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 247, in get_containing_app_config
self.check_apps_ready()
File "/usr/local/lib/python3.5/dist-packages/django/apps/registry.py", line 125, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

我非常感谢您的回复

更新#2

如果我在 wsgi.py 中使用此代码:
import os

from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()

堆栈跟踪将变为:( mmemp 是我的应用程序的名称):
 mod_wsgi (pid=5579): Target WSGI script '/var/www/mmcba/mmemp/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=5579): Exception occurred processing WSGI script '/var/www/mmcba/mmemp/wsgi.py'.
Traceback (most recent call last):
File "/var/www/mmcba/mmemp/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named mmemp.settings

我的虚拟主机配置,这里是:
Listen 80

NameVirtualHost 148.251.218.202:80

<VirtualHost *:80>
ServerAdmin webmaster@mmcba.com
ServerName mmcba.com
ServerAlias www.mmcba.com

WSGIScriptAlias / /var/www/mmcba/mmemp/wsgi.py

<Directory /var/www/mmcba/mmemp>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

最佳答案

如果您使用 django 1.7+,请替换 wsgi.py 的内容有了这个:

import os

from django.core.wsgi import get_wsgi_application

os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
application = get_wsgi_application()

或尝试将以下行添加到 settings.py
import django
django.setup()

有一个类似的问题 here .希望能帮助到你。

关于django - 关于 wsgi.py 中 wsgi 模块的 Ubuntu 16.04 服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45654741/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com