c = template.Context({'now': now})
html = t.render(c) # Just pass {'now': now} instead of cOn Tue, Dec 12, 2017 at 5:08 PM, Al Scham <[email protected]> wrote: > Hi, > > I'm am new to django and am workng through the OverIQ tutoiral at : > https://overiq.com/django/1.10/loading-templates-in-django > > I have followed the instructions to the letter but am getting the > typeerror every time (see subject). > > Heres is my views.py > > from django.shortcuts import render > from django.http import HttpResponse > from django import template > import datetime > > def index(request): > return HttpResponse("Hello Django") > > def today_is(request): > now = datetime.datetime.now() > t = template.loader.get_template('blog/datetime.html') > c = template.Context({'now': now}) > html = t.render(c) > return HttpResponse(html) > > *and here is my template:* > > > <!DOCTYPE html> > <html lang="en"> > <head> > <meta charset="UTF-8"> > <title>Current Time</title> > </head> > <body> > > {#This is a comment #} > {check the existence of now variable in the template using if tag #} > {% if now %} > <p>Current date and time is {{ now }}</p> > {% else %} > <p>now variable is not available</p> > {% endif %} > > </body> > </html> > > *Any help would be aprreciated.* > > *Thanks* > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit https://groups.google.com/d/ > msgid/django-users/bfcbafcb-c748-4a7b-8594-eb22e701b256%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/bfcbafcb-c748-4a7b-8594-eb22e701b256%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAGGVXBPgKDBfDtKSVSxvn9pkWBeK-m2%2BeO4PGHAeSkBdEPqm_Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

