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".
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
Tags
Thread detail
Thread Create
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.