This is ** 6th **, a memorandum of making a game record management app for shogi using Django.
The working environment this time is as follows
Also, Django's directory structure looks like this:
- kifu_app_project/
- kifu_app_project/
- __init__.py
- setting.py
- urls.py
- wsgi.py
- kifu_app/
- migrations/
- templates/
- index.html
- informationList.html
- informationDetail.html
- __init__.py
- admin.py
- apps.py
- models.py
- tests.py
- urls.py
- views.py
- manage.py
- .gitignore
--Inherit Template --Include Template
I've created Templates up to the last time, but considering that I'm going to create a number of Templates, I want to make it as easy as possible ...
For example, inside the <head>
tag will be the same for any template.
Also, I think that maintainability will improve if the same parts are organized.
Template inheritance is like fitting one template into another.
First, create the original Template.
base.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.js"></script>
<title>
{% block title %}
{% endblock %}
</title>
</head>
<body>
{% block body_content %}
{% endblock %}
</body>
</html>
Enclose the part you want to fit later in {% block <block name>%}
{% endblock%}
.
I don't feel much benefit from this alone ... However, it's easy to change only this Template to load things like Bootstrap in the future.
Next, create a template for the person to fit. Modify informationList.html as an example.
informaitonList.html
{% extends "base.html" %}
{% block title %}
Kifu APP
{% endblock %}
{% block body_content %}
{% for each_data in object_list %}
<h3>{{ each_data }}</h3>
<table border="1">
<tr>
<td><a href="{% url 'kifu_app:informationDetail' each_data.id %}">{{ each_data.date }}</a></td>
<td>{{ each_data.sente }}</td>
<td>{{ each_data.gote }}</td>
<td>{{ each_data.small_class }}</td>
</tr>
</table>
{% endfor %}
{% endblock %}
First, load the Template to be fitted with {% extends" Template name "%}
.
After that, in the base mentioned earlier, enclose the contents with a block that corresponds to the place you want to fit.
For example, on the detailed screen of the game record, I think that it is easier to use if there is a shogi board. However, such a shogi board may be used for other than the detail screen.
Then, the idea of include is to * manage the "shogi board" as a part and read the part where necessary *. This also makes maintenance easier.
First, create the following HTML file as a "part"
html:part:html
<h3>here"parts"Will come</h3>
To load such a "part", do the following in the Template you want to load:
informationDetail.html
{% extends "base.html" %}
{% block title %}
Kifu APP
{% endblock %}
{% block body_content %}
<h3>{{ object }}</h3>
<table border="1">
<tr>
<td>{{ object.id }}</td>
<td>{{ object.date }}</td>
<td>{{ object.sente }}</td>
<td>{{ object.gote }}</td>
<td>{{ object.result }}</td>
<td>{{ object.my_result }}</td>
<td>{{ object.small_class }}</td>
<td>{{ object.created_at }}</td>
<td>{{ object.updated_at }}</td>
</tr>
</table>
{% include 'part.html' %} <!--Loading here-->
{% endblock %}
With just this, you can load and display the part called part.html!
Create .env