December 2016
Beginner to intermediate
694 pages
14h 2m
English
In the previous chapter, you may have noticed something peculiar in how we returned the text in our example views. Namely, the HTML was hard-coded directly in our Python code, like this:
def current_datetime(request):
now = datetime.datetime.now()
html = "It is now %s." % now
return HttpResponse(html)
Although this technique was convenient for the purpose of explaining how views work, it's not a good idea to hard-code HTML directly into your views. Here's why:
Read now
Unlock full access