zoukankan      html  css  js  c++  java
  • django-模板之URL标签(五)

    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 %}

     

  • 相关阅读:
    POJ 1401 Factorial
    POJ 2407 Relatives(欧拉函数)
    POJ 1730 Perfect Pth Powers(唯一分解定理)
    POJ 2262 Goldbach's Conjecture(Eratosthenes筛法)
    POJ 2551 Ones
    POJ 1163 The Triangle
    POJ 3356 AGTC
    POJ 2192 Zipper
    POJ 1080 Human Gene Functions
    POJ 1159 Palindrome(最长公共子序列)
  • 原文地址:https://www.cnblogs.com/xiximayou/p/11743821.html
Copyright © 2011-2022 走看看