-
-
Save miguelgr/d9e082cf8f5af8afc911 to your computer and use it in GitHub Desktop.
python micro-django.py runserver <port>
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
# http://programming.oreilly.com/2014/04/simplifying-django.html | |
import os | |
import sys | |
BASE_PATH = os.path.dirname(__file__) | |
from django.conf import settings | |
from django.conf.urls import patterns, url | |
from django.template.response import TemplateResponse | |
from django.core.management import execute_from_command_line | |
settings.configure( | |
DEBUG=True, | |
SECRET_KEY='e#xs6-=-0e63+hjg8l_kv_fjmv2w71j7ee(1nm)7%e9w7rsadz',# get_env_setting("SECRET_KEY") #keep it as environment variable | |
ROOT_URLCONF=sys.modules[__name__], | |
TEMPLATE_DIRS=( | |
os.path.join(BASE_PATH, 'templates'), | |
), | |
) | |
def index(request): | |
return TemplateResponse(request, 'index.html', { | |
'request': request | |
}) | |
urlpatterns = patterns('', | |
url(r'^$', index, name='index'), | |
) | |
# from os import environ | |
# def get_env_setting(setting): | |
# """ Get the environment setting or return exception """ | |
# try: | |
# return environ[setting] | |
# except KeyError: | |
# error_msg = "Set the %s env variable" % setting | |
# raise ImproperlyConfigured(error_msg) | |
if __name__ == "__main__": | |
execute_from_command_line(sys.argv) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment