Skip to content

Instantly share code, notes, and snippets.

@AndBondStyle
Last active March 8, 2018 21:43
Show Gist options
  • Select an option

  • Save AndBondStyle/bd4158ddaa6c0b59ca03af9bd1db964c to your computer and use it in GitHub Desktop.

Select an option

Save AndBondStyle/bd4158ddaa6c0b59ca03af9bd1db964c to your computer and use it in GitHub Desktop.
Single-file Django server
from django.template.backends.django import DjangoTemplates
from django.core.wsgi import get_wsgi_application
from django.core.management import call_command
from os.path import basename, dirname
from django.shortcuts import render
from django.conf import settings
from django.urls import path
# VIEWS
home = lambda r: render(r, 'home.html')
# URLS
urlpatterns = [
path('', home, name='home'),
]
# SETTINGS
if not settings.configured:
FILE = basename(__file__).split('.')[0]
PATH = dirname(__file__)
BACKEND = FILE + '.DjangoTemplates'
settings.configure(
DEBUG=True,
MIDDLEWARE_CLASSES=[],
ROOT_URLCONF=FILE,
TEMPLATES=[{'BACKEND': BACKEND, 'DIRS': [PATH]}]
)
if __name__ == '__main__':
application = get_wsgi_application()
call_command('runserver', '80')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment