Skip to content

Personal website encompassing a portfolio, course platform, and blog. Checkout my free course and article.

Notifications You must be signed in to change notification settings

aliahadmd/djportfolio

Repository files navigation

important

when deploy to github then remove or comments psycopg2 and use psycopg2-binary

css

https://andybrewer.github.io/mvp/

server

pm2 start ecosystem.config.js pm2 restart ecosystem.config.js pm2 stop ecosystem.config.js pm2 status

Deploy with Vercel

Django + Vercel

This image shows how to use Django 4 on Vercel with Serverless Functions using the Python Runtime.

Demo

https://django-template.vercel.app/

How it Works

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.

Running Locally

python manage.py runserver

Your Django application is now available at http:https://localhost:8000.

One-Click Deploy

Deploy the image using Vercel:

Deploy with Vercel

About

Personal website encompassing a portfolio, course platform, and blog. Checkout my free course and article.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published