day51作业

时间:2022-10-20 20:09:21

利用无名有名分组加反向解析完成用户数据的编辑和删除功能

目录结构

day51:

  • app01
  • day51
  • static
  • templates
  • manage.py

功能截图

day51作业

代码实现

day51/urls.py

from django.conf.urls import url,include
from django.contrib import admin urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^app01/', include('app01.urls')),
]
app01/urls.py

from django.conf.urls import url,include
from app01 import views urlpatterns = [
url(r'^index/', views.index,name='i'),
url(r'add_user/', views.add_user, name='add'),
url(r'edit_user/(\d+)',views.edit_user,name='edit'),
url(r'delete_user/(\d+)',views.delete_user,name='delete'),
]
app01/views.py

from django.shortcuts import render,HttpResponse,redirect,reverse
from app01 import models # Create your views here.
def index(request):
user_list = models.User.objects.all()
return render(request,'index.html',{"user_list":user_list}) # 新增用户
def add_user(request):
if request.method == "POST":
username = request.POST.get('username')
age = request.POST.get('age')
addr = request.POST.get('addr')
salary = request.POST.get('salary') models.User.objects.create(username=username,age=age,addr=addr,salary=salary)
return redirect(reverse('i'))
return render(request,'add_user.html') def edit_user(request,edit_id):
user_obj = models.User.objects.filter(id=edit_id)
if request.method == "POST":
username = request.POST.get('username')
age = request.POST.get('age')
addr = request.POST.get('addr')
salary = request.POST.get('salary') models.User.objects.filter(id=edit_id).update(username=username,age=age,addr=addr,salary=salary)
return redirect(reverse('i'))
return render(request,'edit_user.html',{"user_obj":user_obj[0]}) def delete_user(request,delete_id):
models.User.objects.filter(id=delete_id).delete()
return redirect(reverse('i'))
数据库配置

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'day51',
'USER':'root',
'PASSWORD':'123',
'HOST':'192.168.32.130',
'CHARSET':'utf8',
}
}
index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
{% load static %}
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
<script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
</head>
<body> {#导航条#}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'i' %}">Home</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="{% url 'i' %}">用户列表</a></li>
{# <li><a href="#">作者列表</a></li>#}
<li class="dropdown"></li>
</ul>
<form class="navbar-form navbar-left">
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">登录 / 注册</a></li>
<li class="dropdown">
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav> <div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="panel panel-primary">
<div class="panel panel-heading panel-primary text-center ">用户列表
<span class="glyphicon glyphicon-book pull-right"></span>
</div> <div class="panel-body"> <!--搜索按钮-->
<form class="form-inline">
<div class="form-group">
<label class="sr-only" for="exampleInputAmount">搜索</label>
<div class="input-group">
<input type="text" class="form-control" id="exampleInputAmount" placeholder="搜索">
</div>
</div> <button type="submit" class="btn btn-primary">搜索</button>
<!--新增按钮-->
<a href="{% url 'add' %}" class="btn btn-success pull-right">新增</a>
</form> <br> <table class="table-hover table-bordered table-striped table">
<thead>
<tr>
<th>序号</th>
<th>用户名</th>
<th>年龄</th>
<th>地址</th>
<th>薪资</th>
<th>操作</th>
</tr>
</thead>
<tbody>
{% for user in user_list %}
<tr>
<td>{{ user.id }}</td>
<td>{{ user.username }}</td>
<td>{{ user.age }}</td>
<td>{{ user.addr }}</td>
<td>{{ user.salary }}</td>
<td>
<a href="{% url 'edit' user.id %}" class="btn btn-primary">编辑</a>
<a href="{% url 'delete' user.id %}" class="btn-danger btn" onclick="return confirm('是否确认要删除')">删除</a>
</td>
</tr>
{% endfor %} </tbody>
</table> {# 分页开始#}
<nav aria-label="Page navigation" class="text-center">
<ul class="pagination">
<li>
<a href="#" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
<li><a href="#">1</a></li>
<li><a href="#">2</a></li>
<li><a href="#">3</a></li>
<li><a href="#">4</a></li>
<li><a href="#">5</a></li>
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
</ul>
</nav>
{# 分页结束#} </div>
</div> </div>
</div>
</div>
</body>
</html>
add_user.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
{% load static %}
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
<script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
</head>
<body> {#导航条#}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'i' %}">Home</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="{% url 'i' %}">用户列表</a></li>
{# <li><a href="#">作者列表</a></li>#}
<li class="dropdown"></li>
</ul>
<form class="navbar-form navbar-left">
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">登录 / 注册</a></li>
<li class="dropdown">
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav> <div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="panel panel-primary">
<div class="panel panel-heading panel-primary text-center">添加用户
<span class="glyphicon glyphicon-book pull-right"></span>
</div> <div class="panel-body">
{# <br>#}
{# <div>#}
<form action="" method="post">
<p>
用户名:
<input type="text" name="username" class="form-control">
</p>
<p>
年龄:
<input type="text" name="age" class="form-control">
</p>
<p>
地址:
<input type="text" name="addr" class="form-control">
</p>
<p>
薪资:
<input type="text" name="salary" class="form-control">
</p>
<p>
<input type="submit" value="提交" class="btn btn-primary">
</p>
</form> </div>
</div> </div>
</div>
</div>
</body>
</html>
edit_user.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
{% load static %}
<link rel="stylesheet" href="{% static 'bootstrap/css/bootstrap.min.css' %}">
<script src="{% static 'bootstrap/js/bootstrap.min.js' %}"></script>
</head>
<body> {#导航条#}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{% url 'i' %}">Home</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="{% url 'i' %}">用户列表</a></li>
{# <li><a href="#">作者列表</a></li>#}
<li class="dropdown"></li>
</ul>
<form class="navbar-form navbar-left">
</form>
<ul class="nav navbar-nav navbar-right">
<li><a href="#">登录 / 注册</a></li>
<li class="dropdown">
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
</ul>
</li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav> <div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2"> <div class="panel panel-primary">
<div class="panel panel-heading panel-primary text-center">编辑用户
<span class="glyphicon glyphicon-book pull-right"></span>
</div> <div class="panel-body">
{# <br>#}
{# <div>#}
<form action="" method="post">
<p>
用户名:
<input type="text" name="username" value="{{ user_obj.username }}" class="form-control">
</p>
<p>
年龄:
<input type="text" name="age" value="{{ user_obj.age }}" class="form-control">
</p>
<p>
地址:
<input type="text" name="addr" value="{{ user_obj.addr }}" class="form-control">
</p>
<p>
薪资:
<input type="text" name="salary" value="{{ user_obj.salary }}" class="form-control">
</p>
<p>
<input type="submit" value="提交" class="btn btn-primary">
</p>
</form>
{# </div>#} </div>
</div> </div>
</div>
</div>
</body>
</html>

day51作业的更多相关文章

  1. day51 作业

    用html搭建一个注册页面 <!DOCTYPE html> <html lang="en"> <head> <meta charset=& ...

  2. python 每周作业

    day2:python的简介与认识day2:# 1.写一个登录程序# username# passwd# 让用户输入账号和密码,输入用户和密码输入正确的话# 提示你 xxx,欢迎登录,今天的日期是xx ...

  3. python10作业思路及源码:类Fabric主机管理程序开发(仅供参考)

    类Fabric主机管理程序开发 一,作业要求 1, 运行程序列出主机组或者主机列表(已完成) 2,选择指定主机或主机组(已完成) 3,选择主机或主机组传送文件(上传/下载)(已完成) 4,充分使用多线 ...

  4. SQLServer2005创建定时作业任务

    SQLServer定时作业任务:即数据库自动按照定时执行的作业任务,具有周期性不需要人工干预的特点 创建步骤:(使用最高权限的账户登录--sa) 一.启动SQL Server代理(SQL Server ...

  5. 使用T-SQL找出执行时间过长的作业

        有些时候,有些作业遇到问题执行时间过长,因此我写了一个脚本可以根据历史记录,找出执行时间过长的作业,在监控中就可以及时发现这些作业并尽早解决,代码如下:   SELECT sj.name , ...

  6. T-SQL检查停止的复制作业代理,并启动

        有时候搭建的复制在作业比较多的时候,会因为某些情况导致代理停止或出错,如果分发代理时间停止稍微过长可能导致复制延期,从而需要从新初始化复制,带来问题.因此我写了一个脚本定期检查处于停止状态的分 ...

  7. Python09作业思路及源码:高级FTP服务器开发(仅供参考)

    高级FTP服务器开发 一,作业要求 高级FTP服务器开发 用户加密认证(完成) 多用户同时登陆(完成) 每个用户有不同家目录且只能访问自己的家目录(完成) 对用户进行磁盘配额,不同用户配额可不同(完成 ...

  8. 个人作业week3——代码复审

    1.     软件工程师的成长 感想 看了这么多博客,收获颇丰.一方面是对大牛们的计算机之路有了一定的了解,另一方面还是态度最重要,或者说用不用功最重要.这些博客里好些都是九几年或者零几年就开始学习编 ...

  9. 个人作业-week2:关于微软必应词典的案例分析

    第一部分 调研,评测 评测基于微软必应词典Android5.2.2客户端,手机型号为MI NOTE LTE,Android版本为6.0.1. 软件bug:关于这方面,其实有一些疑问.因为相对于市面上其 ...

随机推荐

  1. 关于Sa系列用户不能登录,只能本地windows身份验证的说明

  2. MVC5网站开发之一 总体概述

    由于前几次都没能写完,这次年底总算有*时间了,又想继续捣鼓一下.于是下载了VS 2015专业版(不知为什么我特别钟爱专业版,而不喜欢企业版).由于以前的教训,我这次决定写一个极简的Deom,简到什么 ...

  3. 用 Navicat 写mysql的游标

    千言万语也比不上一个简单直接明了的小例子: CREATE PROCEDURE pro_users() begin DECLARE myid int; DECLARE no int; ); ); ); ...

  4. 在c&plus;&plus;程序中执行DOS命令

    转自博客:http://blog.csdn.net/ypist/article/details/8485049 #1,system()方式 在C盘根目录下新建文件夹,名称为12: system(&qu ...

  5. Android ListView中添加不同的多种布局

    最近做项目要使用ListView加载不同的布局,由于自己写的代码不能贴出,故找了一篇自认为比较好的blog给分享出来,希望对用到此项技术的同学有点帮助. http://logc.at/2011/10/ ...

  6. LeetCode 35&period; Search Insert Position (搜索嵌入的位置)

    Given a sorted array and a target value, return the index if the target is found. If not, return the ...

  7. java 文件创建 调试

    BufferedWriter bw=new BufferedWriter(new FileWriter("/2.txt")); bw.write("hello" ...

  8. 【codeforces 870F】Paths

    Description You are given a positive integer n. Let's build a graph on vertices 1, 2, ..., n in such ...

  9. HDU 5552 Bus Routes(NTT&plus;分治)

    题意 给定 \(n\) 个点,任意连边,每条边有 \(m\) 种颜色可选,求带环连通图的方案数. \(1\leq n\leq 10000\) \(1\leq m < 2^{31}\) 思路 直接 ...

  10. eclipse&sol;STS 提升注解提示速度

    window -- preference -- 输入content -- java -- editor -- content Assist --auto delay 选项 改为100或者更低  提示速 ...