Deploying a Django 5 Project to Vercel

posted 3 min read

Deploying a Django 5 Project to Vercel

This guide explains how to deploy a Django 5 project to Vercel using the wemake-django-template (as of February 2, 2025). The template is based on Django 5.1.4 and Python 3.12, emphasizing code quality and security. More details are available on the documentation page.


Important Considerations

  • Deployment Bundle Size: Vercel limits Serverless Functions to an uncompressed size of 250 MB (including layers), enforced by AWS.
  • Dependency Management: Install dependencies via a requirements.txt file or a Pipfile with Pipfile.lock.
  • Python Version: Only Python 3.9 or 3.12 are supported.

If these requirements don’t match your project needs, Vercel might not be the best fit.

Prerequisites

  • Vercel Account & CLI: Ensure a Vercel account is active and the CLI is installed.

Project Setup

1. Bootstrap Your Project

Begin by using cookiecutter with the wemake-django-template:

cookiecutter gh:wemake-services/wemake-django-template

When prompted, provide values as needed. For example:


You've downloaded /Users/kelvin/.cookiecutters/wemake-django-template before. Is it okay to delete and re-download it? [y/n] (y): y
  [1/4] project_name (test-project): django-vercel
  [2/4] project_verbose_name (Test Project): Deploy django to vercel
  [3/4] project_domain (myapp.com): vercel.com
  [4/4] organization (wemake.services): github.com/vousmeevoyez

Configuring the Project for Vercel

2. Generate requirements.txt

Since the template uses Poetry for dependency management, export dependencies to a requirements.txt file (without hashes for faster resolution):

poetry export --without-hashes --format=requirements.txt > requirements.txt

3. Update WSGI Settings

Vercel requires the entry point to be named app or handler. Make the following changes:

  • In server/wsgi.py: Replace the default callable with:
    app = get_wsgi_application()
    
  • In server/settings/components/common.py: Set the WSGI application:
    WSGI_APPLICATION = 'server.wsgi.app'
    

4. (Optional) Database Setup

For simplicity, this guide uses SQLite for deployment. For production, consider PostgreSQL. To allow flexibility using dj-database-url, update the database configuration:

DATABASES = {
    'default': dj_database_url.config(default=config('DATABASE_URL'))
}

5. Create vercel.json

Add a vercel.json file at the project root with the following content to configure the runtime and entrypoint:

{
  "version": 2,
  "builds": [
    {
      "src": "server/wsgi.py",
      "use": "@vercel/python",
      "config": {"runtime": "python3.12"}
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "server/wsgi.py"
    }
  ]
}

Deploying to Vercel

With the project configured, deploy using the Vercel CLI:

vercel

The CLI will prompt for details, for example:


Vercel CLI 34.3.1
? Set up and deploy “~/apps/django-vercel”? yes
? Which scope do you want to deploy to? kelvinswarna's projects
? Link to existing project? no
? What’s your project’s name? django-vercel
? In which directory is your code located? ./
...
✅  Production: https://django-vercel-d5fwpcj3u-kelvinswarnas-projects.vercel.app

To update the production deployment later, run:

vercel --prod
Tip: If you plan to use a database other than SQLite, configure PostgreSQL with a managed service like Supabase or Neon for better scalability and reliability.
Note: Vercel's serverless environment does not support long-running background tasks. If your Django app relies on Celery or similar background task processing, consider using an external task queue service like Redis with AWS Lambda or Cloud Run.
Caution: Vercel enforces a 250 MB uncompressed limit for serverless functions. If your Django project has many dependencies or large assets, your deployment might fail. Optimize dependencies and exclude unnecessary files to stay within this limit.

Conclusion

By following these steps, your Django 5 project is now configured to meet Vercel’s requirements and deployed successfully. This guide covered exporting dependencies, adjusting WSGI settings, optionally setting up the database configuration, and creating the required vercel.json file.

Enjoy your deployed Django application on Vercel!

If you read this far, tweet to the author to show them you care. Tweet a Thanks
Kelvin, this is a great guide! The steps are clear and easy to follow. One thing I'd suggest adding is a bit more detail on optimizing dependencies for the 250 MB serverless limit—could save people from deployment issues. Also, since you’re using SQLite for simplicity, maybe a quick mention of why PostgreSQL would be better for production would help too. Otherwise, awesome work! Keep it up! Cheers....

More Posts

When to Choose FastAPI Over Django or Flask: A Comprehensive Guide with Practical Examples

Esubalew - Jan 22

PWA and Django #3: Online and offline resources in a PWA - Developing Progressive Web Applications with Django

Andres Alvarez - Nov 27, 2024

Django TemplateDoesNotExist Solved

Tejas Vaij - Jun 1, 2024

Python on the web - High cost of synchronous uWSGI

Vivek Sahu - Apr 30, 2024

5 Vs code extension's to increase your developer productivity

minhaz.ratul - Dec 5, 2024
chevron_left