8.3 Django Template Inheritance

master
Jason Zhu 2020-11-11 18:03:02 +11:00
parent d209a9a794
commit 430167db83
3 changed files with 32 additions and 29 deletions

View File

@ -0,0 +1,15 @@
<html>
<head>
<title>To-Do lists</title>
</head>
<body>
<h1>{% block header_text %}{% endblock %}</h1>
<form method="POST" action="{% block form_action %}{% endblock %}">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
{% block table %}
{% endblock %}
</body>
</html>

View File

@ -1,12 +1,5 @@
<html> {% extends 'base.html' %}
<head>
<title>To-Do lists</title> {% block header_text %}Start a new To-Do list{% endblock %}
</head>
<body> {% block form_action %}/lists/new{% endblock %}
<h1>Your To-Do list</h1>
<form method="POST" action="/lists/new">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
</body>
</html>

View File

@ -1,18 +1,13 @@
<html> {% extends 'base.html' %}
<head>
<title>To-Do lists</title>
</head>
<body>
<h1>Your To-Do list</h1>
<form method="POST" action="/lists/{{ list.id }}/add_item">
<input name="item_text" id="id_new_item" placeholder="Enter a to-do item" />
{% csrf_token %}
</form>
<table id="id_list_table"> {% block header_text %}Your To-Do list{% endblock %}
{% for item in list.item_set.all %}
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr> {% block form_action %}/lists/{{ list.id }}/add_item{% endblock %}
{% endfor %}
</table> {% block table %}
</body> <table id="id_list_table">
</html> {% for item in list.item_set.all %}
<tr><td>{{ forloop.counter }}: {{ item.text }}</td></tr>
{% endfor %}
</table>
{% endblock %}