You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PythonAnywhere部署Django应用时出现WSGI运行错误及ModuleNotFoundError求助

问题原因

  • sys.path添加的路径错误:你当前给path变量赋值的是settings.py的完整文件路径,而Python搜索模块时需要的是包含src包的父目录路径,不是单个文件路径。按你给出的路径,src包所在的父目录是/home/HumBen/AMC_Inventory/venv/src,把这个路径加入sys.path才能让Python识别到src模块。
  • WSGI应用变量名错误:PythonAnywhere的WSGI规范要求暴露的应用变量名必须是application,你当前定义的是stockmgmt,服务器找不到对应的应用入口。

修复后的WSGI文件内容

# +++++++++++ DJANGO +++++++++++
# To use your own Django app use code like this:
import os
import sys

# 改为包含src包的父目录路径
path = '/home/HumBen/AMC_Inventory/venv/src'

if path not in sys.path:
    sys.path.insert(0, path)

os.environ['DJANGO_SETTINGS_MODULE'] = 'src.settings'

## Uncomment the lines below depending on your Django version
###### then, for Django >=1.5:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
###### or, for older Django <=1.4
#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()

修改完成后保存WSGI文件,到PythonAnywhere的Web面板点击重载站点即可生效。

内容的提问来源于stack exchange,提问作者HumBen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.29 00:09:03