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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -