
Templates in Django
Templates are the HTML files with Django's template language ({{ }} and {% %})
We can place this templates folder either inside each app as: appname/templates or globally in the project as: project/templates and configure it in the settings.py under TEMPLATES.
- Templates are used for combining markup language with the data from our views.
- Templates are designed for presentation, not logic.
Django has its own template language and supports alternatives like Jinja2 too.
variables:
{{ post }}
control logic:
{% for item in items %}
{{ item.name }}
{% endfor %}
we use render() in views.py to combine template + context:
def home(request):
return render(request, 'accounts/login.html')

Join Techsnap Creators
Share your knowledge and earn ??
Want to showcase your tech expertise and get rewarded for your insights? Join the Techsnap creator network!
Write insightful blogs, stay ahead of industry trends, and grow your professional brand while helping others in the community.
Ready to make an impact?

Comments