.
├── db.sqlite3
├── manage.py
├── myormLogin
│   ├── __init__.py
│   ├── __pycache__
│   │   ├── __init__.cpython-36.pyc
│   │   ├── settings.cpython-36.pyc
│   │   ├── urls.cpython-36.pyc
│   │   └── wsgi.cpython-36.pyc
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── ormlogin
├── __init__.py
├── __pycache__
│   ├── __init__.cpython-36.pyc
│   ├── admin.cpython-36.pyc
│   ├── models.cpython-36.pyc
│   ├── urls.cpython-36.pyc
│   └── views.cpython-36.pyc
├── admin.py
├── apps.py
├── migrations
│   ├── 0001_initial.py
│   ├── 0002_auto_20180724_0924.py
│   ├── __init__.py
│   └── __pycache__
│   ├── 0001_initial.cpython-36.pyc
│   ├── 0002_auto_20180724_0924.cpython-36.pyc
│   └── __init__.cpython-36.pyc
├── models.py
├── templates
│   ├── index.html
│   ├── login.html
│   ├── user_detail.html
│   ├── user_edit.html
│   └── user_info.html
├── tests.py
├── urls.py
└── views.py

项目名/urls.py

from django.contrib import admin
from django.urls import path,include urlpatterns = [
path('admin/', admin.site.urls),
path('cmdb/',include("ormlogin.urls"))
]

app/urls.py

from django.urls import path
from ormlogin import views urlpatterns = [
path('login/',views.login),
path('index/', views.index),
path('user_info/',views.user_info),
path('userdetail/<int:nid>/',views.user_detail),
path('userdel/<int:nid>/',views.user_del),
path('useredit/<int:nid>/',views.user_edit),
]

models.py

from django.db import models

# Create your models here.
class UserInfo(models.Model):
username = models.CharField(max_length=32)
password = models.CharField(max_length=64)

views.py

from django.shortcuts import render, HttpResponse, redirect
from ormlogin import models # Create your views here. def index(request):
return render(request, 'index.html') def login(request):
if request.method == "GET":
return render(request, "login.html")
elif request.method == "POST":
u = request.POST.get('user')
p = request.POST.get('pwd')
obj = models.UserInfo.objects.filter(username=u, password=p).first()
if obj == None:
return redirect('/cmdb/index/')
return render(request, "login.html")
else:
return redirect(request, "/index/") def user_info(request):
if request.method == "GET":
user_list = models.UserInfo.objects.all()
return render(request, "user_info.html", {"user_list": user_list})
elif request.method == "POST":
u = request.POST.get('user')
p = request.POST.get('pwd')
models.UserInfo.objects.create(username=u, password=p)
return redirect('/cmdb/user_info/') def user_detail(request, nid):
obj = models.UserInfo.objects.filter(id=nid).first()
return render(request, 'user_detail.html', {'obj': obj}) def user_del(request, nid):
obj = models.UserInfo.objects.filter(id=nid).delete()
return redirect('/cmdb/user_info/') def user_edit(request, nid):
if request.method == "GET":
obj = models.UserInfo.objects.filter(id=nid).first()
return render(request, 'user_edit.html', {'obj': obj})
elif request.method == "POST":
nid = request.POST.get('id')
u = request.POST.get('username')
p = request.POST.get('password')
models.UserInfo.objects.filter(id=nid).update(username=u, password=p)
return redirect('/cmdb/user_info/')

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div>
欢迎您!
</div> <div>
<a class="menu" href="/cmdb/user_info/">管理1</a>
<a class="menu" href="/cmdb/user_group/">管理2</a>
<a class="menu">管理3</a>
</div>
</body>
</html>

login.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/cmdb/login/" method="POST"> <p>
<input type="text" name="user" placeholder="用户名">
</p>
<p>
<input type="text" name="pwd" placeholder="密码">
</p>
<input type="submit" value="提交">
</form>
</body>
</html>

user_detail.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="height: 48px; background-color: black;color: white">
欢迎您!
</div>
<div style="position: absolute; top: 48px; bottom: 0; left:0; width: 200px; background-color: aqua">
<a class="menu" href="/cmdb/user_info/">管理1</a>
<a class="menu" href="cmdb/user_group/">管理2</a>
<a class="menu">管理3</a>
</div>
<div style="position: absolute; top: 48px; left: 210px; bottom: 0;right: 0; overflow: auto">
<h1>用户详细信息:</h1>
<h5>{{ obj.id }}</h5>
<h5>{{ obj.name }}</h5>
<h5>{{ obj.password }}</h5>
</div>
</body>
</html>

user_edit.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="height: 48px; background-color: black;color: white">
欢迎您!
</div>
<div style="position: absolute; top: 48px; bottom: 0; left:0; width: 200px; background-color: aqua">
<a class="menu" href="/cmdb/user_info/">管理1</a>
<a class="menu" href="cmdb/user_group/">管理2</a>
<a class="menu">管理3</a>
</div>
<div style="position: absolute; top: 48px; left: 210px; bottom: 0;right: 0; overflow: auto">
<h1>编辑用户:</h1>
<form method="POST" action="/cmdb/useredit/{{ obj.id }}/">
<input style="display: none" type="text" name="id" value="{{ obj.id }}"/>
<input type="text" name="username" value="{{ obj.username }}"/>
<input type="text" name="password" value="{{ obj.password }}"/>
<input type="submit" value="修改"/>
</form>
</div>
</body>
</html>

user_info.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div style="height: 48px; background-color: black;color: white">
欢迎您!
</div>
<div style="position: absolute; top: 48px; bottom: 0; left:0; width: 200px; background-color: aqua">
<a class="menu" href="/cmdb/user_info/">管理1</a>
<a class="menu" href="cmdb/user_group/">管理2</a>
<a class="menu">管理3</a>
</div>
<div style="position: absolute; top: 48px; left: 210px; bottom: 0;right: 0; overflow: auto">
<h1>编辑用户:</h1>
<form method="POST" action="/cmdb/useredit/{{ obj.id }}/">
<input style="display: none" type="text" name="id" value="{{ obj.id }}"/>
<input type="text" name="username" value="{{ obj.username }}"/>
<input type="text" name="password" value="{{ obj.password }}"/>
<input type="submit" value="修改"/>
</form>
</div>
</body>
</html>

python3 manage.py runserver 跑起来

浏览器输入地址:

127.0.0.1:8000/cmdb/login

直接登陆,随便输,没有做用户名和密码的验证

在管理界面可以新添加用户,删除,编辑

最新文章

  1. dispatch_set_target_queue 说明
  2. 为什么我坚持学习C语言?
  3. 简单粗暴下载Spring
  4. JAVA基础知识之多线程——线程池
  5. uva 624
  6. 微信内移动前端开发抓包调试工具fiddler使用教程
  7. [置顶] 【cocos2d-x入门实战】微信飞机大战之三:飞机要起飞了
  8. Javabyte[]数组和十六进制String之间的转换Util------包含案例和代码
  9. MFC中的HOOK编程
  10. 两端对齐布局与text-align:justify
  11. 《数据结构与算法分析:C语言描述》读书笔记------List的C语言实现
  12. pycharm安装破解go插件
  13. iframe父页面和子页面获取元素和js变量
  14. Linux 常用命令和使用技巧
  15. 【译】5. Java反射——方法
  16. ffmpeg 视频实现各种特效
  17. python实现切换代理ip
  18. spring单元测试的基本配置
  19. par函数family参数-控制文字的字体
  20. [BZOJ 2763][JLOI 2011] 飞行路线

热门文章

  1. ScheduledThreadPoolExecutor 源码分析
  2. 剑指offer(2):字符串
  3. mac 添加mysql的环境变量和删除mysql
  4. Common Linux Commands 日常工作常用Linux命令
  5. Linq查询语法(2)
  6. cJSON使用笔记
  7. .net core 自定义中间件
  8. git多账号配置,同时使用多个代码托管平台
  9. BAT程序员常用的开发工具,建议收藏!
  10. 浏览器是怎样工作的(一):基础知识 转载http://ued.ctrip.com/blog/how-browsers-work-i-basic-knowledge.html