django 用户登陆注册

时间:2022-12-31 11:57:05

注册登陆

django 用户登陆注册

views.py

#!/usr/bin/env python
# -*- coding:utf- -*-
from django.shortcuts import render,render_to_response,redirect,HttpResponse
import models
# Create your views here. def addusertype(request):
data = models.usertpye.objects.all()
for item in data:
print item.id,item.name ret = {'status':"",'typedata':data} if request.method == 'POST':
name = request.POST.get('name',None)
is_empty = all([name])
if is_empty:
models.usertpye.objects.create(name = name)
ret['status'] = '用户权限添加成功'
else:
ret['status'] = '输入的用户权限为空' return render_to_response('app01/addusertype.html',ret) def addgroup(request):
groupdata = models.usergroup.objects.all()
ret = {'status':"",'data':groupdata} if request.method == 'POST':
groupname = request.POST.get('groupname',None)
is_empty = all([groupname])
if is_empty:
models.usergroup.objects.create(groupname = groupname)
ret['status'] = '用户组添加成功'
else:
ret['status'] = '用户组不能为空' return render_to_response('app01/addgroup.html',ret) def adduser(request):
groupdata = models.usergroup.objects.all()
typedata = models.usertpye.objects.all()
userdata = models.user.objects.all()
ret = {'status':"",'group':groupdata,'type':typedata,'user':userdata} if request.method == 'POST':
username = request.POST.get('username',None)
password = request.POST.get('password',None)
email = request.POST.get('email',None)
type_id = request.POST.get('typeuser',None)
group_id = request.POST.get('groupuser',None) t1 = models.usertpye.objects.get(id = type_id)
g1 = models.usergroup.objects.get(id = group_id) is_empty = all([username,password,email,type_id,group_id])
if is_empty:
u1 = models.user.objects.create(username=username,password=password,email=email,usertpye_id=t1)
g1.user_group_manytomany.add(u1)
else:
ret['status'] = '填写的内容不能为空' # obj = models.user.objects.filter(usertpye_id__groupname='DBA组')
# print obj.query return render_to_response('app01/adduser.html',ret)

models.py

from __future__ import unicode_literals

from django.db import models

# Create your models here.

class usertpye(models.Model):
name = models.CharField(max_length=) class user(models.Model):
username = models.CharField(max_length=)
password = models.CharField(max_length=)
email = models.EmailField()
usertpye_id = models.ForeignKey('usertpye') class usergroup(models.Model):
groupname = models.CharField(max_length=)
user_group_manytomany = models.ManyToManyField('user') class asset(models.Model):
hostname = models.CharField(max_length=)
ip = models.GenericIPAddressField()
SN = models.CharField(max_length=)
manageip = models.GenericIPAddressField()
buydata = models.DateField(auto_now=True)
serverdata = models.DateField(auto_now_add=True)
pinpai = models.CharField(max_length=)
memory = models.CharField(max_length=)
cpu = models.CharField(max_length=)
usergroup_id = models.ForeignKey('usergroup')

urls.py

urlpatterns = [
url(r'^addusertype/',views.addusertype),
url(r'^addgroup/',views.addgroup),
url(r'^adduser/',views.adduser),
]

addgroup.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>主机管理</title>
<style type="text/css">
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
} #customers th
{
font-size:.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
} #customers tr.alt td
{
color:#;
background-color:#EAF2D3;
}
</style>
</head>
<body>
<div class="div">
<h1> 添加权限 </h1>
<form action="/app01/addgroup/" method="POST">
<p><input type="text" name="groupname" placeholder="groupname"/></p>
<input type="submit" name="增加"/><span style="color: #cc0000;font-size: 12px">{{ status }}</span>
</form>
</div>
<hr/>
<div>
<h1> 显示用户组 </h1>
<table border="1px">
<tr>
<td>ID</td>
<td>groupname</td>
</tr>
{% for item in data %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.groupname }}</td>
</tr>
{% endfor %}
</table>
</div>
</body>
</html>

adduser.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>主机管理</title>
<style type="text/css">
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
} #customers th
{
font-size:.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
} #customers tr.alt td
{
color:#;
background-color:#EAF2D3;
}
</style>
</head>
<body>
<div class="div">
<h1> 添加权限 </h1>
<form action="/app01/adduser/" method="POST">
<p><input type="text" name="username" placeholder="username"/></p>
<p><input type="text" name="password" placeholder="password"/></p>
<p><input type="text" name="email" placeholder="email"/></p>
<p><select name="typeuser">
{% for item in type %}
<option value="{{ item.id }}">{{ item.name }}</option>
{% endfor %}
</select>
</p>
<p><select name="groupuser">
{% for item in group %}
<option value="{{ item.id }}">{{ item.groupname }}</option>
{% endfor %}
</select>
</p>
<input type="submit" name="增加"/><span style="color: #cc0000;font-size: 12px">{{ status }}</span>
</form>
</div>
<hr/>
<div>
<h1> 显示用户组 </h1> <table border="1px">
<tr>
<td>ID</td>
<td>usrname</td>
<td>password</td>
<td>email</td>
<td>usertype</td>
<td>usergroup</td>
</tr>
{% for item in user %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.username }}</td>
<td>{{ item.password }}</td>
<td>{{ item.email }}</td>
<td>{{ item.usertpye_id.name }}</td>
<td>{{ item.usertpye_id.groupname }}</td>
</tr>
{% endfor %}
</table> </div>
</body>
</html>

addusertype.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>主机管理</title>
<style type="text/css">
#customers td, #customers th
{
font-size:1em;
border:1px solid #98bf21;
padding:3px 7px 2px 7px;
} #customers th
{
font-size:.1em;
text-align:left;
padding-top:5px;
padding-bottom:4px;
background-color:#A7C942;
color:#ffffff;
} #customers tr.alt td
{
color:#;
background-color:#EAF2D3;
}
</style>
</head>
<body>
<div class="div">
<h1> 添加权限 </h1>
<form action="/app01/addusertype/" method="POST">
<p><input type="text" name="name" placeholder="name"/></p>
<input type="submit" name="增加"/><span style="color: #cc0000;font-size: 12px">{{ status }}</span>
</form>
</div>
<hr/>
<div>
<h1> 显示所有权限名称 </h1>
<table border="1px">
<tr>
<td>ID</td>
<td>Name</td>
</tr>
{% for item in typedata %}
<tr>
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
</tr>
{% endfor %}
</table>
</div>
</body>
</html>

django 用户登陆注册的更多相关文章

  1. 用户登陆注册【JDBC版】

    前言 在讲解Web开发模式的时候,曾经写过XML版的用户登陆注册案例!现在在原有的项目上,使用数据库版来完成用户的登陆注册!如果不了解的朋友,可以看看我Web开发模式的博文! 本来使用的是XML文件作 ...

  2. 《java入门第一季》模拟用户登陆注册案例集合版

    需求:校验用户名和密码,登陆成功后玩猜数字小游戏. 在这里先写集合版.后面还有IO版.数据库版. 一.猜数字小游戏类: 猜数字小游戏的代码见博客:http://blog.csdn.net/qq_320 ...

  3. Django用户登陆以及跳转后台管理页面3

    Django用户登陆以及跳转后台管理页面1http://www.cnblogs.com/ujq3/p/7891774.html Django用户登陆以及跳转后台管理页面2http://www.cnbl ...

  4. Django用户登陆以及跳转后台管理页面2

    请先写好以下,再来替换文件 Django用户登陆以及跳转后台管理页面1http://www.cnblogs.com/ujq3/p/7891774.html from django.shortcuts ...

  5. 函数式编程做用户登陆注册练习-pycharm上

    def login(username,password): """ 用户登陆 :param username: 用户名 :param password:密码 :retur ...

  6. Django 用户登陆访问限制 &commat;login&lowbar;required

    #用户登陆访问限制 from django.http import HttpResponseRedirect #只有登录了才能看到页面 #设置方法一:指定特定管理员才能访问 def main(requ ...

  7. jsp&plus;servlet&plus;mysql简单实现用户登陆注册

    原码,项目中遇到的错误,解决方法,文章最后有链接可以获取 项目简介 *有的网友说在修改和删除时会触发error,建议各位不要去把用户名命名为中文! 功能描述 登陆,注册,用户一览表,修改,删除,添加, ...

  8. Python学习笔记&lowbar;05&colon;使用Flask&plus;MySQL实现用户登陆注册以及增删查改操作

    前言:本文代码参考自两篇英文博客,具体来源点击文末代码链接中文档说明. (PS:代码运行Python版本为2.7.14) 运行效果: 首页: 注册页面: 登陆界面: 管理员登陆后界面: 添加.删除.修 ...

  9. Django用户登陆以及跳转后台管理页面1

    """S14Djngo URL Configuration The `urlpatterns` list routes URLs to views. For more i ...

随机推荐

  1. Struts框架——(二)Struts原理with登录实例

    二. Struts基本工作流程 假设现在有以下情景: 用户正在浏览一个用STRUTS的技术构建的网站主页,主页上有个登陆表单,用户填好登陆名和密码,单击"登陆"按钮,就激活了以下一 ...

  2. 【温故Delphi】之VCL消息机制小结

    TObject消息分派 procedure Dispatch(var Message); virtual; #负责分派消息到特定VCL组件的事件处理函数 procedure DefaultHandle ...

  3. redhat安装VMware tools的方法

    如果我们仔细看的话, 就会发现在VMware软件界面的左下角处显示着 "you don't have VMware Tools installed",即我们还没安装VMware T ...

  4. sql多行转一行,以逗号隔开

    --SELECT ff= stuff((select ','+cast(WorkOrderNo as varchar)-- FROM dbo.TB_WorkOrder c -- where tpl.P ...

  5. Huffman Coding 哈夫曼编码

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4096079.html 使用优先队列实现,需要注意以下几点: 1.在使用priority_qu ...

  6. 重载 C 函数

    在 clang 的扩展下,可以重载 C 函数,例如重载 sin 函数: float __attribute__((overloadable)) sin(float x) { return sinf(x ...

  7. 设计模式学习--组合模式,c&plus;&plus;代码

    下面是组合模式的UML类图: <span style="font-family:Microsoft YaHei;font-size:18px;"><span st ...

  8. x86汇编寄存器,函数参数入栈说明

    https://en.wikipedia.org/wiki/X86_calling_conventions

  9. MyBatis中传入参数parameterType类型详解

    前言 Mybatis的Mapper文件中的select.insert.update.delete元素中有一个parameterType属性,用于对应的mapper接口方法接受的参数类型.本文主要给大家 ...

  10. logstash匹配多行日志

    在工作中,遇到一个问题就是日志的处理,首选的方案就是ELFK(filebeat+logstash+es+kibana) 因为之前使用过logstash采集日志的时候,非常的消耗系统的资源,所以这里我选 ...