Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why use HTML in Django Template
#1
I am confuse in usage of HTML(.html) in Django templates,
why we can not use .py (python) in Django templates ?
Reply
#2
Every web site is ultimately HTML, the following link explains it well: https://docs.djangoproject.com/en/2.2/topics/templates/
Reply
#3
If would be cool in browser could read .py,but that's not the case browsers read html.
Template allow us to transfer Python-like code into html.

So eg on server.
my_list = [1,2,3]
Template.
<ul>
  {% for post in my_list %}
    <li>{{ post }}</li>
  {% endfor %}
</ul>
What the browser read and render from this template is real html,as that's what the browser understand.
<ul>
  <li>1</li>
  <li>2</li>
  <li>3</li>
</ul>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  django - reset password template rwahdan 2 1,957 Dec-26-2021, 09:09 PM
Last Post: Jeff900
  show csv file in flask template.html rr28rizal 8 34,532 Apr-12-2021, 09:24 AM
Last Post: adamabusamra
Lightbulb Hypertag. New language for HTML templating w/ Django support mwojnars 0 1,744 Apr-06-2021, 12:53 PM
Last Post: mwojnars
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,536 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Django serving wrong template at the wrong address with malformed urls.py (redactor a Drone4four 2 2,533 Aug-17-2020, 01:09 PM
Last Post: Drone4four
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 2,329 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  Posting html values to views/models in Django Malt 1 2,129 Sep-04-2019, 01:44 PM
Last Post: fishhook
  Django: How to automatically substitute a variable in the admin page at Django 1.11? m0ntecr1st0 3 3,247 Jun-30-2019, 12:21 AM
Last Post: scidam
  Passing a query value from a Bottle html template to a route with an encoding nikos 0 2,894 Sep-30-2018, 03:29 AM
Last Post: nikos
  convert html to pdf in django site shahpy 4 5,979 Aug-17-2018, 11:10 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020