Maybe you want to test your first django template but keep getting this annoying error message. You certainly getting this error because you are misusing the shell. You are using python shell instead of a django managed shell. Saying this, what do i really mean. Suppose you want to test the following template:
cmd>django-admin.py startproject dummyProject
cmd> cd dummyProject
dummyProject> python manage.py shell
>>>
>>> from django.template import Context, Template
>>> t = Template("Hello {{ name }}.")
>>> c = Context({"name": "World !"})
>>> t.render(c)
Hello World !
Congratulation , you just run your first django template.
>>> from django.template import Context, TemplateInstead of running the above script from the python shell, go the command prompt ( if you are using winodws os)
>>> t = Template("Hello {{ name }}.")
>>> c = Context({"name": "World"})
>>> t.render(c)
cmd>django-admin.py startproject dummyProject
cmd> cd dummyProject
dummyProject> python manage.py shell
>>>
>>> from django.template import Context, Template
>>> t = Template("Hello {{ name }}.")
>>> c = Context({"name": "World !"})
>>> t.render(c)
Hello World !
Congratulation , you just run your first django template.
No comments:
Post a Comment