Django Deployment on Render: ModuleNotFoundError for WSGI Application The Problem

Demo of the Project

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:application

  • Environment: 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

  1. Created a virtual environment and installed django, gunicorn, and whitenoise.

  2. Froze requirements: pip freeze > requirements.txt.

  3. Set ALLOWED_HOSTS = ['your-app-name.onrender.com', 'localhost'] in settings.py.

  4. Pushed the code to a public GitHub repository.

  5. 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"?

Running gunicorn foremanbportfolio.wsgi:application from within Foreman-B_MyPortfolio will not run the server because gunicorn will not be able to resolve foremanbportfolio correctly. That package simply does not exist in Foreman-B_MyPortfolio. Take a second look at your repository structure and confirm my verdict.

However, what actually exists in your repository is the package portfolio. It is here that the WSGI module for the synchronous server gateway exists. Run gunicorn portfolio.wsgi:application from within Foreman-B_MyPortfolio instead. That way gunicorn will resolve paths correctly.

Вернуться на верх