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>

    页面展示效果:
     
  • 相关阅读:
    Axis2 1.7.4构建项目
    MyBatis之传入参数
    eclipse快捷键
    WEB-INF目录下的jsp页面如何访问?
    web-content和web-info目录问题
    http响应报文和http请求报文 详细信息
    极光推送知识点2
    极光推送别名、标签怎么理解
    推送的通知和自定义消息区别
    个推
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12037063.html
Copyright © 2011-2022 走看看