How to Deploy Django on Vercel?

Recently I consulted a client where I helped him deploy his django application on vercel successfully. So, I thought of documenting this process so as to help you deploy your django application on vercel for free.

Step 1: Add a vercel.json Configuration File

In the root directory of your Django project, create a file named vercel.json and add the following configuration:

{
    "builds": [{
        "src": "yourproject/wsgi.py",
        "use": "@vercel/python",
        "config": { "maxLambdaSize": "15mb", "runtime": "python3.9" }
    }],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "yourproject/wsgi.py"
        }
    ]
}

Replace yourproject with the name of your Django project.

Explanation:

builds : Specifies the entry point of the application and python runtime.

routes : Maps all incoming requests to the wsgi.py file of your project.

Step 2: Update settings.py

Locate the ALLOWED_HOSTS configuration in your settings.py file and update it as follows:

ALLOWED_HOSTS = ['*']

Step 3: Modify wsgi.py

At the end of your wsgi.py file, add the following line:

app = application

This ensures that the WSGI application object is exposed and recognized by Vercel during deployment Make sure application = get_wsgi_application() is present above

Step 4: Install Vercel CLI

To deploy your application, you need the Vercel CLI. Open your terminal and install it globally using npm:

npm install -g vercel

Step 5: Log In to Vercel

Authenticate your Vercel account by running:

vercel login

Step 6: Deploy Your Application

Navigate to the root directory of your Django project and run:

vercel deploy

You’ll be prompted with a series of questions:

  1. Set up and deploy? Choose “Yes.”

  2. Which scope should contain your project? Select your dashboard.

  3. Link to existing project? Choose “No.”

  4. What’s your project’s name? Provide a name for your project (e.g., deployapp).

  5. In which directory is your code located? Specify ./ (current directory).

Once completed, your Django application will be deployed.

Step 7: Verify Deployment and View Logs

Accessing Your Application

After a successful deployment, Vercel will provide a URL where your application is hosted. Open this URL in your browser to verify that the application is working as expected.

Viewing Logs

To check runtime logs:

vercel logs <deployment_url>

To inspect build logs:

vercel inspect --logs <deployment_url>

Replace <deployment_url> with the URL provided by Vercel after deployment.


Happy coding!