Common django templates

So, the general views are pretty cool, but what interests me is what the general template is.

so, for example, I can give it an object, and it will just tostring it for me.

or if I give him a list, he simply iterates over the objects and builds them like ul (or tr or something else that he considers necessary).

for most applications you will not need this. I just quickly threw something for a friend (a bar application, if you know), and I don’t feel like writing templates.

+3
source share
2 answers

django, django.contrib.admin django.contrib.databrowse. , , django. :

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)

, , , , html, pprint:

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: ... , :

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()
+5

, , , .

, , object_list.html object_detail.html

, , . "" , .

+1

Source: https://habr.com/ru/post/1721317/


All Articles