Foreword
When we open a website, found that the top and bottom of each page of content is almost, in order to improve the reusability of code, we can use these head, the bottom of the function code is encapsulated into a single utility, similar to the python in the package, use when calling on it, django there similar functionality, include realized.
Public content
Each page of the site generally, the top navigation bar, middle of the page content, there are some links at the bottom. During the design process we can put these separate code.
hello / templates / top.html separate out
<section>
<h1>顶部导航
</h1>
<p>python自动化-北京-流水</p> <hr>
</section>
hello / templates / end.html separate out
<section>
<br><br><br><br><hr>
<h1>底部导航</h1>
<p>底部一些友情链接啊</p>
</section>
hello / templates / base.html content
include grammar
hello/templates/page1.html
hello / views.py view function
urls.py add the access path
Access address browser http://127.0.0.1:8000/page1/
will be able to see the effect of the
Arguments
Top.html common part and which can be passed end.html variables, such as
<section>
< H1 of> top navigation </ h1 of>
< - P> Python automation {{name}} </ P> < HR>
</section>
Corresponding to the view function
def page1(request):
context = {"name": "流水"}
return render(request, 'page1.html', context)