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

     

  • 相关阅读:
    mapbox-gl开发:deck.gl轨迹图效果
    vscode双击选中单词,设置短横线不分隔
    CSS自定义滚动条样式,兼容IE浏览器
    flv 视频播放器
    mapbox、echarts实现地图流动效果
    echarts 小时图
    deckgl-triplayer流动效果
    vue使用flv视频监控组件
    qt学习中遇到的问题及处理方法
    GitHub入门
  • 原文地址:https://www.cnblogs.com/xiximayou/p/11743821.html
Copyright © 2020-2023  润新知