展示用户列表
- 方向
- 展示用户列表
- url
- 函数
- 获取用户所有的信息
- 基于HTML给他个渲染
views.py
from django.shortcuts import render, HttpResponse, redirect
# Create your views here.
from app01.models import text_into
# 注意:函数默认要有个参数
def index(request):
data_list = text_into.objects.all()
print(data_list)
return render(request, "text.html", {
"data_list": data_list})
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>测试</title>
</head>
<body>
<h1>用户列表</h1>
<table border="1">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>密码</th>
<th>年龄</th>
</tr>
</thead>
<tbody>
{% for foo in data_list %}
<tr>
<td>{
{ foo.id }}</td>
<td>{
{ foo.name }}</td>
<td>{
{ foo.password }}</td>
<td>{
{ foo.age }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
添加用户
- 方向
- url
- 函数
- GET,看到页面,输入内容。
- POST,提交 ->写入到数据库。
views.py
import requests
from django.shortcuts import render