Skip to content

Instantly share code, notes, and snippets.

@awinabi
Created July 10, 2021 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awinabi/31c8ca60cc7fd807990c63dd54641e19 to your computer and use it in GitHub Desktop.
Save awinabi/31c8ca60cc7fd807990c63dd54641e19 to your computer and use it in GitHub Desktop.
Single file Django App
import os
from pathlib import Path
from django.conf import settings
from django.core.wsgi import get_wsgi_application
from django.urls import path, include
from django.http import HttpResponse
from django.shortcuts import render
BASE_DIR = Path(__file__).resolve().parent
settings.configure(
ROOT_URLCONF=__name__,
SECRET_KEY = 'your-randomly-generated-secret-key',
INSTALLED_APPS=[
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles"
],
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
}
],
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
],
)
def hello_world(request):
return HttpResponse("Hello, Django!")
def movie_list(request):
return render(request, 'movies.html', {})
urlpatterns = [
path('', hello_world),
path('movies', movie_list),
]
application = get_wsgi_application()
<!doctype html>
<html lang="en">
<body>
<h1>Movies</h1>
<ul>
<li>Judas and the Black Messiah</li>
<li>One Night in Miami</li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment