Last active
March 8, 2018 21:43
-
-
Save AndBondStyle/bd4158ddaa6c0b59ca03af9bd1db964c to your computer and use it in GitHub Desktop.
Single-file Django server
This file contains hidden or 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
| 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