Django 1.10项目部署至PythonAnywhere后无法访问求助
Let’s walk through the most common issues that could be stopping your Rango app from loading at danielcirstea.pythonanywhere.com/rango, even after setting DEBUG=False and configuring your host:
Double-check your
ALLOWED_HOSTSsetting
Make sure yoursettings.pyhas the exact domain with no typos:ALLOWED_HOSTS = ['danielcirstea.pythonanywhere.com']Skip extra slashes or
wwwunless you’re actively using that subdomain. If you want to support both, use['danielcirstea.pythonanywhere.com', 'www.danielcirstea.pythonanywhere.com'].Verify your WSGI configuration
PythonAnywhere’s WSGI file needs to correctly point to your Django project’s root and settings. For example, if your project lives at/home/danielcirstea/rango_project, your WSGI file should look like this:import os import sys # Add your project path to sys.path project_path = '/home/danielcirstea/rango_project' if project_path not in sys.path: sys.path.insert(0, project_path) # Set the Django settings module os.environ['DJANGO_SETTINGS_MODULE'] = 'rango_project.settings' # Activate virtual environment if you're using one activate_this = '/home/danielcirstea/.virtualenvs/rango_env/bin/activate_this.py' with open(activate_this) as file_: exec(file_.read(), dict(__file__=activate_this)) from django.core.wsgi import get_wsgi_application application = get_wsgi_application()Also confirm that
DJANGO_SETTINGS_MODULEmatches your project’s structure—if your settings are inrango/settings.py, use'rango.settings'instead.Fix static file configuration (critical for
DEBUG=False)
WhenDEBUGis off, Django won’t serve static files automatically. Follow these steps:- Run
python manage.py collectstaticin your project’s Bash console. This copies all static files into the directory specified bySTATIC_ROOTinsettings.py. - In PythonAnywhere’s Web tab, add a static file mapping:
- URL:
/static/ - Directory:
/home/danielcirstea/rango_project/staticfiles(or whatever yourSTATIC_ROOTpath is)
Without this, your app might throw errors or load with broken styling.
- URL:
- Run
Confirm your virtual environment setup
If you’re using a virtual environment, make sure you installed Django and all project dependencies inside it. In PythonAnywhere’s Web tab, under "Virtualenv", double-check the path matches your environment (e.g.,/home/danielcirstea/.virtualenvs/rango_env). If you installed packages globally instead of in the venv, the server might not find them.Check the error logs
This is the fastest way to pinpoint the issue! In PythonAnywhere’s Web tab, look at:- Error log: Shows runtime issues like
DisallowedHosterrors, missing imports, or database connection problems - Server log: Displays startup messages and configuration warnings
The logs will give you specific details about what’s failing—for example, aDisallowedHosterror means you need to tweakALLOWED_HOSTS, while a static file missing error points to a misconfigured static mapping.
- Error log: Shows runtime issues like
If you share snippets from your error logs, we can narrow down the problem even further!
内容的提问来源于stack exchange,提问作者user9092892

