zoukankan      html  css  js  c++  java
  • 展示出版社:写上URL地址对应函数、函数当中查询出所有的出版社、对象交给模板、循环对象拿出每条数据展示

    URL:

    from django.conf.urls import url
    from django.contrib import admin
    from app01 import views

    urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^publisher/', views.publisher),
    ]

    views:
    from django.shortcuts import render
    from app01 import models

    # Create your views here.

    def publisher(request):
    #查询出所有出版社的信息:
    all_publishers = models.Publisher.objects.all()
    #返回一个页面:第一个参数request、HTML页面、字典形式:第一个是字典的key字符串形式、第二个是从数据库的中name
    return render(request,"publisher.html",{"all_publishers":all_publishers})

    HTML:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    </head>
    <body>

    <table border="1">
    <thead>
    <tr>
    <th>序号</th>
    <th>id</th>
    <th>出版社名称</th>
    </tr>
    </thead>
    <tbody>
    {% for publisher in all_publishers %}
    <tr>
    <td>{{ forloop.counter }}</td>
    <td>{{ publisher.pk }}</td>
    <td>{{ publisher.name }}</td>
    </tr>
    {% endfor %}
    </tbody>
    </table>
    </body>
    </html>

    页面展示效果:
     
  • 相关阅读:
    设置与获取Cookie
    事件对象详解
    兼容各浏览器的鼠标滚轮事件
    正则对象与正则表达式的基础学习
    Ajax 学习
    禅道使用流程概述
    Fiddler、Maven介绍
    Locust安装教程与使用
    常用工具软件包下载地址
    SVN合并步骤
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12037063.html
Copyright © 2011-2022 走看看