Django Deployment on Render: ModuleNotFoundError for WSGI Application The Problem
The Problem
I am attempting to deploy a Django portfolio project to Render. While the project runs perfectly on my local machine using python manage.py runserver, the deployment fails during the build process.
The Render logs indicate that Gunicorn cannot locate the project module, even though the folder structure appears correct in my GitHub repository.
Error Log:
Bash
==> Running 'gunicorn foremanbportfolio.wsgi:application --bind 0.0.0.0:$PORT'
Traceback (most recent call last):
...
ModuleNotFoundError: No module named 'foremanbportfolio'
==> Exited with status 1
Minimal Reproducible Example
1. Project Structure: My repository is structured as follows:
Foreman-B_MyPortfolio/
├── manage.py
├── portfolio/
│ ├── __init__.py
│ ├── settings.py
│ ├── urls.py
│ ├── wsgi.py
│ └── asgi.py
├── pages/
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ ├── views.py
│ └── static/ # App-specific static
│ └── pages/
│ ├── css/
│ ├── js/
│ └── images/
├── static/ # Global static folder (all large assets)
│ ├── admin/ # Admin CSS/JS/images
│ ├── bootstrap/
│ ├── css/
│ ├── js/
│ ├── img/
│ └── rest_framework/
├── templates/
│ └── pages/
│ └── foremanbportfolio.html
└── staticfiles/
2. Current Configuration on Render:
Build Command:
./build.sh(installs requirements and runs collectstatic)Start Command:
gunicorn foremanbportfolio.wsgi:applicationEnvironment: Python 3.13
3. Relevant wsgi.py content:
Python
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'foremanbportfolio.settings')
application = get_wsgi_application()
Steps Taken to Publish
Created a virtual environment and installed
django,gunicorn, andwhitenoise.Froze requirements:
pip freeze > requirements.txt.Set
ALLOWED_HOSTS = ['your-app-name.onrender.com', 'localhost']insettings.py.Pushed the code to a public GitHub repository.
Connected the repository to a New Web Service on Render.
My Question
Why is Gunicorn unable to find the foremanbportfolio module on Render when the file exists in the root of my repository? Is there a specific way I should be referencing the WSGI application path in the Render "Start Command"?