簡體   English   中英

在生產服務器上部署期間,我在 django 應用程序中收到 500 內部服務器錯誤 ModuleNotFoundError: No module named 'main' (wsgi:error)

[英]I am getting 500 Internal Server Error in django app during deloying on production server ModuleNotFoundError: No module named 'main' (wsgi:error)

我想使用 mod_wsgi 為我的項目提供服務。 當我運行開發服務器時,它已啟動,但在生產服務器上出現錯誤。我的操作系統是 RedHat 並使用配置了 python3-mod_wsgi 的 httpd(apache) 虛擬主機。

這是我的錯誤

 [Tue Oct 05 14:01:48.998236 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] mod_wsgi (pid=423542): Failed to exec Python script file '/var/www/public_html/main/main/wsgi.py'. [Tue Oct 05 14:01:48.998291 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] mod_wsgi (pid=423542): Exception occurred processing WSGI script '/var/www/public_html/main/main/wsgi.py'. [Tue Oct 05 14:01:48.998461 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] Traceback (most recent call last): [Tue Oct 05 14:01:48.998506 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/var/www/public_html/main/main/wsgi.py", line 17, in <module> [Tue Oct 05 14:01:48.998523 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] application = get_wsgi_application() [Tue Oct 05 14:01:48.998530 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application [Tue Oct 05 14:01:48.998534 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] django.setup(set_prefix=False) [Tue Oct 05 14:01:48.998540 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/__init__.py", line 19, in setup [Tue Oct 05 14:01:48.998543 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) [Tue Oct 05 14:01:48.998548 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 76, in __getattr__ [Tue Oct 05 14:01:48.998552 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] self._setup(name) [Tue Oct 05 14:01:48.998557 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 63, in _setup [Tue Oct 05 14:01:48.998560 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] self._wrapped = Settings(settings_module) [Tue Oct 05 14:01:48.998565 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/local/lib/python3.6/site-packages/django/conf/__init__.py", line 142, in __init__ [Tue Oct 05 14:01:48.998569 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] mod = importlib.import_module(self.SETTINGS_MODULE) [Tue Oct 05 14:01:48.998574 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module [Tue Oct 05 14:01:48.998577 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] return _bootstrap._gcd_import(name[level:], package, level) [Tue Oct 05 14:01:48.998582 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 994, in _gcd_import [Tue Oct 05 14:01:48.998587 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 971, in _find_and_load [Tue Oct 05 14:01:48.998592 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked [Tue Oct 05 14:01:48.998597 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed [Tue Oct 05 14:01:48.998602 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 994, in _gcd_import [Tue Oct 05 14:01:48.998614 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 971, in _find_and_load [Tue Oct 05 14:01:48.998619 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked [Tue Oct 05 14:01:48.998633 2021] [wsgi:error] [pid 423542:tid 140143400638208] [remote 209.141.62.185:36776] ModuleNotFoundError: No module named 'main'

這是我的項目 wsgi.py 文件

 import os import sys #from django.conf import settings from django.core.wsgi import get_wsgi_application #sys.path.append('/var/www/public_html/main/') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings') application = get_wsgi_application()

我將我的 wsgi.py 文件更改為此現在它正在工作

 """ WSGI config for main project. It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ """ import os import sys from django.core.wsgi import get_wsgi_application sys.path.append('/var/www/public_html/') os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'main.settings') application = get_wsgi_application()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM