Syntax
1. Variable
{{}}
e.g.
<html><body>{{ now }}</body></html>
2. for loop
{% for x in list %}
{% endfor %}
e.g.
<ul>
{% for item in list %}
<li>{{ item }}</li>
{% endfor %}
</ul>
3. if else
{% if %}
{% else %}
{% endif %}
e.g.
{% if true %}
<p> it is a true part</p>
{% else %}
<p> it is a false part</p>
{% endif %}
This is what we should write in html file. However, we should define a function to pass these variables.
We should define a function in views.py
def get_index_page(request):
all_article = Article.objects.all()
return render(request, 'app1/index.html',
{
'article_list' : all_article
})
After that, we should set content in urls.py
path('index', app1.views.get_index_page)
Comments
Post a Comment