when deploy to github then remove or comments psycopg2 and use psycopg2-binary
https://andybrewer.github.io/mvp/
pm2 start ecosystem.config.js
pm2 restart ecosystem.config.js
pm2 stop ecosystem.config.js
pm2 status
This image shows how to use Django 4 on Vercel with Serverless Functions using the Python Runtime.
https://django-template.vercel.app/
Our Django application, image
is configured as an installed application in core/settings.py
:
# core/settings.py
INSTALLED_APPS = [
# ...
'image',
]
We allow "*.vercel.app" subdomains in ALLOWED_HOSTS
, in addition to 127.0.0.1:
# core/settings.py
ALLOWED_HOSTS = ['127.0.0.1', '.vercel.app']
The wsgi
module must use a public variable named app
to expose the WSGI application:
# core/wsgi.py
app = get_wsgi_application()
The corresponding WSGI_APPLICATION
setting is configured to use the app
variable from the core.wsgi
module:
# core/settings.py
WSGI_APPLICATION = 'core.wsgi.app'
There is a single view which renders the current time in image/views.py
:
# image/views.py
from datetime import datetime
from django.http import HttpResponse
def index(request):
now = datetime.now()
html = f'''
<html>
<body>
<h1>Hello from Vercel!</h1>
<p>The current time is { now }.</p>
</body>
</html>
'''
return HttpResponse(html)
This view is exposed a URL through image/urls.py
:
# image/urls.py
from django.urls import path
from image.views import index
urlpatterns = [
path('', index),
]
Finally, it's made accessible to the Django server inside core/urls.py
:
# core/urls.py
from django.urls import path, include
urlpatterns = [
...
path('', include('image.urls')),
]
This image uses the Web Server Gateway Interface (WSGI) with Django to enable handling requests on Vercel with Serverless Functions.
python manage.py runserver
Your Django application is now available at http://localhost:8000
.
Deploy the image using Vercel: