注册登陆

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 用户登陆访问限制 @login_required

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

  7. jsp+servlet+mysql简单实现用户登陆注册

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

  8. Python学习笔记_05:使用Flask+MySQL实现用户登陆注册以及增删查改操作

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

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

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

随机推荐

  1. Redis在windows环境下的部署

    一.下载 官网地址:http://redis.io/download Git地址:https://github.com/MSOpenTech/redis 注:官方无windows版本,需要window ...

  2. HDU 2089 数位dp入门

    开始学习数位dp...一道昨天看过代码思想的题今天打了近两个小时..最后还是看了别人的代码找bug...(丢丢) 传说院赛要取消 ? ... 这么菜不出去丢人也好吧~ #include<stdi ...

  3. Apache Spark源码走读之11 -- sql的解析与执行

    欢迎转载,转载请注明出处,徽沪一郎. 概要 在即将发布的spark 1.0中有一个新增的功能,即对sql的支持,也就是说可以用sql来对数据进行查询,这对于DBA来说无疑是一大福音,因为以前的知识继续 ...

  4. BNF 巴科斯范式

    BNF 巴科斯范式(BNF: Backus-Naur Form 的缩写)是由 John Backus 和 Peter Naur 首先引入的用来描述计算机语言语法的符号集.现在,几乎每一位新编程语言书籍 ...

  5. SharedPreferences封装类SPUtils

    import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.uti ...

  6. try...except 抛出错误

  7. 6月辞职->帝都生活

    ---恢复内容开始--- 5月初送走了静,有点伤心,但还是忍住没哭. 纠结了一下上哪个班,上不上基础班,不能再拖了,果断交钱报6月份的ios基础班.之前还有个电话面试,怕怕的,考了很多函数的知识,好多 ...

  8. Delphi中如何实现滚动文字

    1.先添加一个Timer控件,其Interval属性设置为50. 2.再添加一个Label控件,Name为Label1. 3.然后在Timer的OnTimer事件添加如下代码: unit Unit13 ...

  9. 兼容加载Xml字符串

    var _loadXML = function(xmlString){ var xmlDoc=null; //支持IE浏览器 if(!window.DOMParser && windo ...

  10. spring3 mvc:方法返回值的学习

    新建后台代码用以测试返回类型,在这里我新建的如下: /** * 项目名称:Spring3mvc demo * Copyright ? 2010-2012 spartacus.org.cn All Ri ...