1、安装Bootstrap4前端框架
使用pip即可
2、加入代码
在settings.py中加入以下内容
INSTALLED_APPS = [
'bootstrap4',]
在product文件夹下创建templates文件夹创建product_manage.html 后加入以下内容
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>product</title> {% load bootstrap4 %} {% bootstrap_css %} {% bootstrap_javascript %} </head> <body role="document"> <!-导航栏-!> <nav class="navbar navbar-expand-sm bg-dark navbar-dark fixed-top"> <div class="container"> <a class="navbar-brand" href="#"> </a> <ul class = "nav justify-content-center"></ul> <ul class = "nav justify-content-end"> <li class="nav-link"><a style="color:white" href ="#">{{ user }}</a> </li> <li class="nav-link"><a style="color:white" href ="#">退出</a> </li> </ul> </div> </nav> <!- 产品列表 -!> <div class="row" style="padding-top:20px;"> <div class = "col-md-11"> <table class="table table-striped"> <thead> <tr><td> </td></tr> <tr><th>ID</th><th>产品名称</th><th>产品描述</th><th>产品负责人</th><th>创建时间</th> </tr> </thead> <tbody> { % for product in products % } <tr> <td>{{ product.id }}</td> <td>{{ product.product_name }}</td> <td>{{ product.product_desc }}</td> <td>{{ product.producter }}</td> <td>{{ product.create_date }}</td> </tr> { % endfor % } </tbody> </table> </div> </div> </body> </html>
后将views.py更改成proviews.py后加入以下内容
from product.models import Product # Create your views here. def product_manage(request): username = request.session.get('user', '') product_list = Product.objects.all() return render(request, 'product_manage.html', {"user": username, "products": product_list})
后将urls.py加入以下内容
path('product_manage/', proviews.product_manage),