If there's a django model for it, you can just stick to django.contrib.admin
or django.contrib.databrowse
. If not, then you might manage by skipping the django template altogether. example:
from django.http import HttpResponse
import datetime
def current_datetime(request):
now = datetime.datetime.now()
html = "<html><body>It is now %s.</body></html>" % now
return HttpResponse(html)
But of course you wanted to avoid even writing that much, so instead of doing html, we can use plain text and the pprint
module:
from django.http import HttpResponse
import datetime
from pprint import pformat
def current_datetime(request):
now = datetime.datetime.now()
return HttpResponse(pformat(now), mimetype="text/plain")
edit: Hmm... this seems like something a view decorator should handle:
from django.http import HttpResponse
import datetime
import pprint
def prettyprint(fun):
return lambda request:HttpResponse(
pprint.pformat(fun(request)), mimetype="text/plain")
@prettyprint
def current_datetime(request):
return datetime.datetime.now()