book/views.py
from django.shortcuts import render def index(request): return render(request,"index.html") def news(request): return render(request,"news.html") def sports(request): return render(request,"sports.html")
book/urls.py
from django.urls import path from . import views urlpatterns = [ path('',views.index,name="index"), path('news/',views.news,name="news"), path('sports/',views.sports,name="sports"), ]
base.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>{{title}}</title> <style> .header { height: 50px; background-color: fuchsia;; } .content{ height:300px; } .footer{ height:50px; background-color: thistle; } </style> </head> <body> <div class="header">Nav Area</div> <div class="content"> {% block content %} {% endblock %} </div> <div class="footer">Foot Area</div> </body> </html>
index.html
{% extends 'base.html'%} {% block content %} <div> <h1><a href={% url 'news'%}>news</a></h1> <h1><a href={% url 'sports'%}>sports</a></h1> </div> {% endblock %}
news.html
{% extends 'base.html'%} {% block content %} <div> <h1>news界面</h1> </div> {% endblock %}
sports.html
{% extends 'base.html'%} {% block content %} <div> <h1>sports界面</h1> </div> {% endblock %}