Vercel deployment error missing variable `handler` or `app` in file "projectname/wsgi.py".

I followed the docs on vercel on how to deploy a python serveless function but on deploying my django rest framework project I get the following error in the functon logs

"Vercel deployment error missing variable `handler` or `app` in file "projectname/wsgi.py".

message profile
Admin
2022-04-01

 This error occurs because vercel is looking for handler or app variable that points to or exposes your project in your projects WSGI.py file. It throws this error because its not being found. I am assuming that your wsgi.py files looks like this

"""
WSGI config for djangoblog project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')

application = get_wsgi_application()

where projectname is the name of your project. All you have to do to fix the error is to add this line of code to your wsgi.py file

app = application

This wil create the app variable that vercel is looking for and point it to your application.

Your wsgi.py file should now look like this

"""
WSGI config for djangoblog project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'projectname.settings')

application = get_wsgi_application()
app = application

 

Add Message

Click on the button below to add a new message to this thread

Tags

Thread detail

Satus: Open
Messages: 1Started: 2022-04-01
loading..

DEVMAESTERS

Newsletter

Services

Frontend Development |Backend Development |Full Website Development |Bootstrap Website upgrades | Website Debbugging | Website Hosting & deployment

Contact

Interested in hiring me or collaborating with me on a project, click on any of the links below to get my social media handle

Or contact me via Tel: (+234)-806-225-7480 | Email: abubakarzakari1703@gmail.com

Copywright@devmaesters.com
Privacy Policy

By using our website,
you agree that devmaesters can store cookies on your device and disclose information in accordance with our privacy policy.