Created
October 9, 2012 13:17
-
-
Save damilare/3858752 to your computer and use it in GitHub Desktop.
Minimal Django - http://myks.org/django-python3/
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
# The first Django site to run on Python 3! | |
# Copyright (c) 2012 Aymeric Augustin | |
# License: https://github.com/django/django/blob/master/LICENSE | |
import os | |
import sys | |
import django | |
from django.conf.urls.defaults import patterns | |
from django.http import HttpResponse, HttpResponseNotFound, HttpResponseServerError | |
from django.template import Context, Template | |
# Settings | |
ROOT_URLCONF = os.path.splitext(os.path.basename(__file__))[0] | |
SECRET_KEY = "********" | |
TIME_ZONE = "Europe/Paris" | |
# View | |
TEMPLATE = """<html> | |
<head> | |
<title>Django on Python 3!</title> | |
<style type="text/css"> | |
body { font-family: Baskerville; margin: 2em auto; width: 42em; } | |
h1, h2 { font-family: Verdana; color: #555; font-weight: normal; } | |
p { text-align: center; line-height: 1.5em; } | |
strong { color: #063; font-size: 120%; font-weight: normal; } | |
pre { background-color: #ddd; color: #222; padding: 1em; } | |
</style> | |
</head> | |
<body> | |
<h1>The first Django site to run on Python 3!</h1> | |
<h2>The assertion</h2> | |
<p>This page was generated by<br> | |
<strong>Django {{ versions.django }}</strong><br> | |
and<br> | |
<strong>Python {{ versions.python }}</strong><br> | |
on {% now "DATETIME_FORMAT" %} (Paris time). | |
</p> | |
<h2>The proof</h2> | |
<pre>{{ code }}</pre> | |
</body> | |
</html>""" | |
def index(request): | |
with open(__file__) as handle: | |
code = handle.read() | |
return HttpResponse(Template(TEMPLATE).render(Context({ | |
'versions': { | |
'django': django.get_version(), | |
'python': sys.version, | |
}, | |
'code': code.replace(SECRET_KEY, '********'), | |
}))) | |
# URL | |
urlpatterns = patterns('', | |
(r'^$', index), | |
) | |
handler404 = lambda request: HttpResponseNotFound( | |
'%r not found' % request.path, content_type='text/plain') | |
handler500 = lambda request: HttpResponseServerError( | |
'something went wrong', content_type='text/plain') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment