html5 - Django Tutorial Part 3 - Code Clarification -
django newbie here. doing django tutorial , although blindly follow code confused how works. {% code %} allows insert python code html, don't line:
<li><a href="/polls/{{ question.id }}/">{{ question.question_text }}
i'd have explanation of how 2 curly brackets variable translates string representation of variable.
i'm asking because tried doing similar operation in interpreter on own , didn't same results.
{% if latest_question_list %} <ul> {% question in latest_question_list %} <li><a href="/polls/{{ question.id }}/">{{ question.question_text }} </a></li> {% endfor %} </ul> {% else %} <p>no polls available.</p> {% endif %}
the {{ variable }}
syntax in django templates used placeholder variable.
if want check how works on console, start django shell:
$ django-admin shell >>> django.template import engines >>> >>> django_engine = engines['django'] >>> template = django_engine.from_string("hello {{ name }}!") >>> context = {'name': 'john'} >>> template.render(context) hello john!
Comments
Post a Comment