-
-
Save awinabi/31c8ca60cc7fd807990c63dd54641e19 to your computer and use it in GitHub Desktop.
Single file Django App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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