from django.db import models

# Create your models here.

class Book(models.Model):
name=models.CharField(max_length=32)
pubDate=models.DateField()
price=models.DecimalField(max_digits=5,decimal_places=2)
publish=models.ForeignKey('Publish')
author=models.ManyToManyField('Author') class Publish(models.Model):
name=models.CharField(max_length=32)
pubdetail=models.OneToOneField('Pubdetail') class Pubdetail(models.Model):
add=models.CharField(max_length=32)
content=models.CharField(max_length=32) class Author(models.Model):
name=models.CharField(max_length=32)
authdetail=models.OneToOneField('Authordetail') class Authordetail(models.Model):
sex=models.CharField(max_length=32)
tel=models.IntegerField()
addr=models.CharField(max_length=32) class User(models.Model):
name=models.CharField(max_length=32)
password=models.CharField(max_length=32)

models.py

from django.shortcuts import render,redirect
from app01 import models
from django.contrib import auth
# Create your views here.
from django.contrib.auth.models import User
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.contrib.auth import logout
def login(request):
s=''
if request.method=='POST': name=request.POST.get('name')
pwd=request.POST.get('password') # res=models.User.objects.filter(name=name,password=pwd)
# if res:
#cookie代码实现
# ret=redirect('/shujichaxun/')
# ret.set_cookie('login','asd',10)
# return ret #auth代码实现
res=auth.authenticate(username=name,password=pwd)
if res:
print('---------------------',request.user.__dict__,type(request.user))
auth.login(request,res)
return redirect('/shujichaxun/') #session实现代码
# request.session['asd']=True
# return redirect('/shujichaxun/')
s='用户名或密码错误'
return render(request,'登录校验.html',{'s':s}) def zhuce(request):
if request.method=='POST':
name=request.POST.get('name')
pwd=request.POST.get('password')
if len(name)>0 and len(pwd)>0 :
#注册方式1: 自建user表
# user_obj=models.User.objects.create(name=name,password=pwd) #用auth模块实现,用django自带的user表
user=User.objects.create_user(username=name,password=pwd)
return redirect('/middle/') return render(request,'zhuce.html') def xiugaimima(request):
s=''
if request.method=='POST':
old_pwd=request.POST.get('oldpwd')
new_pwd=request.POST.get('newpwd')
aga_pwd=request.POST.get('agapwd')
username=request.user
user=User.objects.get(username=username) if user.check_password(old_pwd) and new_pwd==aga_pwd:
user.set_password(new_pwd)
user.save()
return redirect('/login/')
s='原密码不正确或新密码不一致' return render(request,'xiugaimima.html',{'s':s}) def zhuxiao(request): logout(request)
return redirect('/login/') def xieyi(request):
return render(request,'xieyi.html') def middle(request):
return render(request,'middle.html') def shujichaxun(request):
# if request.user.is_authenticated():
# import datetime,random
# # Booklist = []
# # for i in range(100):
# # Booklist.append(models.Book(name="book" + str(i),pubDate=datetime.datetime.now(),price=20 + i,publish_id=2))
# # models.Book.objects.bulk_create(Booklist)
# #
book_list=models.Book.objects.all()
paginator=Paginator(book_list,7) n=paginator.page_range
num=int(request.GET.get("n",1)) #因为get 得到的是字符串
book_list=paginator.page(num) # return render(request,"chaxun.html",{"book_list":book_list,"page_range":page_range,"num":int(num)})
return render(request,"chaxun.html",{"book_list":book_list,'n':n,'num':num}) #cookie实现代码
# res=request.COOKIES.get('login')
# if res=='asd':
# infoDict=models.Book.objects.all()
# return render(request,'chaxun.html',{'infoDict':infoDict})
# return redirect('/login/') # auth模块实现
# if request.user.is_authenticated():
# infoDict=models.Book.objects.all()
# return render(request,'chaxun.html',{'infoDict':infoDict})
# return redirect('/login/') #session实现代码
# res=request.session.get('asd',None)
# if res:
# infoDict=models.Book.objects.all()
# return render(request,'chaxun.html',{'infoDict':infoDict})
# return redirect('/login/') def shujishanchu(request,id):
#cookie实现代码
# res=request.COOKIES.get('login')
# if res=='asd':
# book_obj=models.Book.objects.get(id=id)
# auth_list=book_obj.author.all()
# book_obj.author.remove(*auth_list)
# book_obj.delete()
#
# return redirect('/shujichaxun/')
# return redirect('/login/') #auth模块实现
if request.user.is_authenticated():
book_obj=models.Book.objects.get(id=id)
auth_list=book_obj.author.all()
book_obj.author.remove(*auth_list)
book_obj.delete()
return redirect('/shujichaxun/')
return redirect('/login/') def shujitianjia(request):
#cookie代码实现
# res=request.COOKIES.get('login')
# if res=='asd': #auth模块实现
if request.user.is_authenticated():
if request.method=='POST':
name=request.POST.get('name')
auth=request.POST.getlist('aut')
date=request.POST.get('date')
pub=request.POST.get('pub')
price=request.POST.get('price')
pub_id=models.Publish.objects.filter(name=pub)[0].id
# pub_obj=models.Publish.objects.filter(name=pub)[0] book_obj=models.Book.objects.create(name=name,pubDate=date,price=price,publish_id=pub_id)
# book_obj=models.Book.objects.create(name=name,pubDate=date,price=price,publish=pub_obj)
auth_l=[]
for i in auth:
auth_l.append(models.Author.objects.get(name=i))
book_obj.author.add(*auth_l)
return redirect('/shujichaxun/') authList=models.Author.objects.all()
pubList=models.Publish.objects.all()
return render(request,'tianjia.html',{'authList':authList,'pubList':pubList})
return redirect('/login/') def shujibianji(request):
#cookie代码实现
# res=request.COOKIES.get('login')
# if res=='asd': #auth模块实现
if request.user.is_authenticated():
if request.method=="POST":
id=request.POST.get('id')
name=request.POST.get('name')
auth=request.POST.getlist('aut')
l=[]
for i in auth:
l.append(models.Author.objects.get(name=i))
pubdate=request.POST.get('date')
publish=request.POST.get('pub')
publish_id=models.Publish.objects.get(name=publish).id
price=request.POST.get('price')
book_obj=models.Book.objects.filter(id=id)
book_obj.update(name=name,pubDate=pubdate,price=price,publish_id=publish_id)
book_obj[0].author.clear()
book_obj[0].author.add(*l)
return redirect('/shujichaxun/') id=request.GET.get('id')
name=models.Book.objects.get(id=id).name
pubdate=models.Book.objects.get(id=id).pubDate
price=models.Book.objects.get(id=id).price
publish_obj=models.Book.objects.get(id=id).publish
publish=models.Publish.objects.all()
auth=models.Book.objects.get(id=id).author.all()
authlist=models.Author.objects.all()
return render(request,'bianji.html',{'id':id,'name':name,'pubdate':pubdate,'price':price,'publish':publish,'auth':auth,'authlist':authlist,'publish_obj':publish_obj})
return redirect('/login/') def zuozhechaxun(request):
#cookie 实现代码
# res=request.COOKIES.get('login')
# if res=='asd':
# authlist=models.Author.objects.all()
# return render(request,'zuozhe.html',{'authlist':authlist})
# return redirect('/login/') #auth模块实现
if request.user.is_authenticated():
authlist=models.Author.objects.all()
return render(request,'zuozhe.html',{'authlist':authlist})
return redirect('/login/') #session 实现代码
# res=request.session['asd']
# if res:
# authlist=models.Author.objects.all()
# del request.session['asd']
# return render(request,'zuozhe.html',{'authlist':authlist})
# return redirect('/login/') def chubanshechaxun(request):
#cookie 实现代码
# res=request.COOKIES.get('login')
# if res=='asd':
# publish=models.Publish.objects.all()
# return render(request,'chubanshe.html',{'publish':publish})
# return redirect('/login/') #auth模块实现
if request.user.is_authenticated():
publish=models.Publish.objects.all()
return render(request,'chubanshe.html',{'publish':publish})
return redirect('/login/') def test(request):
name='egon'
age=73
return render(request,'test.html',{'name':name,'age':age})

views.py

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css"/>
<script src="/static/jquery-3.2.1.js"></script>
<script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<style>
.ccc {
margin-top: 70px;
} .clc {
height: 30px;
margin-left: -15px;
text-align: center;
line-height: 30px;
border-radius: 5px;
} .menu {
margin-top: 7px; } .panel {
height: 580px;
} .c2 {
position: relative;
left: 200px;
top: 400px; {# border: 1px solid red;#} } .ccc .row .sidebar {
padding-top: 20px;
height: 600px;
background-color: #f5f5f5;
margin-top: -20px; }
table{
margin-top: -60px;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar"
aria-expanded="false" aria-controls="navbar">
<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="">图书管理系统</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="">设置</a></li>
<li><a href="">帮助</a></li>
<li><a href="/xiugaimima/">修改密码</a></li>
<li><a href="/zhuxiao/">注销</a></li>
<li><a href="">退出</a></li>
</ul>
<form class="navbar-form navbar-right">
<input type="text" class="form-control" placeholder="搜索...">
</form>
</div>
</div>
</nav>
<div class="container-fluid ccc">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<div class="menu">
<a href="/shujichaxun/" style="text-decoration: none"><div class="head bg-primary clc" id="clc1">书 籍 管 理</div></a>
<ul class="nav nav-sidebar hide" id="clc4">
<li class=""><a href="">Overview <span
class="sr-only">(current)</span></a>
</li>
<li><a href="">Reports</a></li>
<li><a href="">Analytics</a></li>
<li><a href="">Export</a></li>
</ul>
</div>
<div class="menu">
<a href="/zuozhechaxun/" style="text-decoration: none"><div class="head bg-primary clc" id="clc2">作 者 管 理</div></a> <ul class="nav nav-sidebar hide" id="clc5">
<li><a href="">Nav item</a></li>
<li><a href="">Nav item again</a></li>
<li><a href="">One more nav</a></li>
<li><a href="">Another nav item</a></li>
<li><a href="">More navigation</a></li>
</ul>
</div>
<div class="menu">
<a href="/chubanshechaxun/" style="text-decoration: none"><div class="head bg-primary clc" id="clc3">出版社管理</div></a> <ul class="nav nav-sidebar hide" id="clc6">
<li><a href="">Nav item again</a></li>
<li><a href="">One more nav</a></li>
<li><a href="">Another nav item</a></li>
</ul>
</div>
</div> {% block tt %}
<div class="col-sm-9 col-md-10 main">
<div class="panel panel-primary">
<div class="panel-heading">书籍信息</div>
<div class="panel-body">
<!-- Button trigger modal -->
<a href="/shujitianjia/"><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
添加
</button></a> <table class="table table-hover">
{# <tr>#}
<thead>
<th>序号</th>
<th>书名</th>
<th>作者</th>
<th>出版日期</th>
<th>出版社</th>
<th>价钱</th> </thead>
{# </tr>#}
{% block tbody %} {% endblock tbody %}
{% endblock tt %}
{# <div class="row c2">#}
{# <nav aria-label="Page navigation " class="pull-right c5">#}
{# <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>#}
</table>
</div>
</div>
</div>
</div> <div class="row">
<div class="col-md-6 col-md-offset-3" style="margin-top: -40px">
<hr/>
<div style="text-align: center">
<a href="">关于我们 |</a>
<a href="">联系我们 |</a>
<a href="">意见与反馈 |</a>
<a href="">友情链接 |</a>
<a href="">公告</a> <div>
<div style="font-size: 13px">
版权所有: Cool
</div>
</div>
</div> </div>
</div>
</div>
<script> {# $('.clc').on('click', function () {#}
{# $(this).parent().siblings().children('ul').addClass('hide');#}
{# $(this).next().toggleClass('hide');#}
{# })#} </script>
</body>
</html>

base.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css"/>
<script src="/static/jquery-3.2.1.js"></script>
<script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row col-md-4 col-md-offset-4" style="margin-top: 100px">
{% block form %}
{% endblock form %}
</div>
</div> </body>
</html>

base2.html

{% extends 'base2.html' %}
{% block form %}
<form action="/shujibianji/" method="post">
{% csrf_token %}
<input type="hidden" name="id" value="{{ id }}"/> <div class="form-group">
<label for="usernaem">书名</label>
<input type="text" class="form-control item" id="usernaem" name="name" value="{{ name }}">
</div> <div class="form-group">
<label for="age">作者</label>
<select name="aut" class="form-control item" id="age" multiple>
{% for aut in authlist %} {% if aut in auth %}
<option selected value="{{ aut.name }}">{{ aut.name }}</option>
{% else %}
<option value="{{ aut.name }}">{{ aut.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="gender">出版时间</label>
<input type="date" class="form-control item" id="gender" name="date" value="{{ pubdate|date:'Y-m-d' }}">
</div>
<div class="form-group">
<label for="publish">出版社</label>
<select name="pub" class="form-control item" id="publish">
{% for pub in publish %}
{% if pub == publish_obj %}
<option selected value="{{ pub.name }}">{{ pub.name }}</option>
{% else %}
<option value="{{ pub.name }}">{{ pub.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="gender1">价格</label>
<input type="text" class="form-control item" id="gender1" name="price" value="{{ price }}">
</div>
<div class="pull-right"><a href="/shujichaxun/">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
</a>
<input type="submit" value="提交" class="btn btn-primary"/> </div>
</form>
{% endblock form %}

bianji.html

{% extends "base.html" %}
{% block tbody %}
<tbody> {% for book in book_list %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ book.name }}</td>
<td>{% for item in book.author.all %}
/{{ item.name }}/
{% endfor %}
</td>
<td>{{ book.pubDate|date:'Y-m-d' }}</td>
<td>{{ book.publish.name }}</td>
<td>{{ book.price }}</td>
<td>
<div class="pull-left">
<a href="/shujishanchu/{{ book.id }}">
<button class="btn btn-danger">删除</button>
</a>
</div>
<a href="/shujibianji?id={{ book.id }}">
<button class="btn btn-success" style="margin-left: 5px">编辑</button>
</a>
</td> </tr>
{% endfor %} <div class="row c2">
<nav aria-label="Page navigation">
<ul class="pagination"> {% if book_list.has_previous %}
<li><a href="/shujichaxun?n={{ book_list.previous_page_number }}" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a></li>
{% else %}
<li class="disabled"><a href="" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a></li> {% endif %} {% for i in n %}
{% if num == i %}
<li class="active"><a href="/shujichaxun?n={{ i }}">{{ i }}</a></li>
{% else %}
<li><a href="/shujichaxun?n={{ i }}">{{ i }}</a></li>
{% endif %}
{% endfor %} {% if book_list.has_next %}
<li><a href="/shujichaxun?n={{ book_list.next_page_number }}#" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a></li> {% else %}
<li class="disabled">
<a href="" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{% endif %} </ul>
</nav>
</div> {% endblock tbody %}

chaxun.html

{% extends 'base.html'%}
{% block tt %}
<div class="col-sm-9 col-md-10 main">
<div class="panel panel-primary">
<div class="panel-heading">出版社信息</div>
<div class="panel-body">
<!-- Button trigger modal -->
<a href="/chubanshetianjia/"><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
添加
</button></a> <table class="table table-hover">
{# <tr>#}
<thead>
<th>序号</th>
<th>社名</th>
<th>地址</th>
<th>详情</th>
</thead>
<tbody>
{% for pub in publish %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ pub.name }}</td>
<td>{{ pub.pubdetail.add }}</td>
<td>{{ pub.pubdetail.content }}</td> <td>
<div class="pull-left">
<a href="/chubansheshanchu/{{ pub.id }}">
<button class="btn btn-danger" >删除</button>
</a>
</div>
<a href="/chubanshebianji/?id={{ pub.id }}">
<button class="btn btn-success" style="margin-left: 5px">编辑</button>
</a>
</td>
</tr>
</tbody>
{% endfor %}
{% endblock tt %}

chubanshe.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="Refresh" content="3;URL=/login/">
{# <meta http-equiv="X-UA-Compatible" content="IE=edge">#}
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css"/>
<script src="/static/jquery-3.2.1.js"></script>
<script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css"/>
<script src="/static/jquery-3.2.1.js"></script>
<script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<style>
body {
background-color: #cccccc;
} .container {
margin-top: 150px; } </style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h4>注册成功,将跳转到登陆页面<a href="/login/">点我直接跳转</a></h4>
</div>
</div>
</div>
</body>
</html>

middle.html

{% extends 'base2.html' %}
{% block form %}
<form action="/shujitianjia/" method="post">
{% csrf_token %}
<div class="form-group">
<label for="usernaem">书名</label>
<input type="text" class="form-control item" id="usernaem" name="name" placeholder="name">
</div> <div class="form-group">
<label for="age">作者</label>
<select name="aut" class="form-control item" id="age" multiple>
{% for aut in authList %}
<option value="{{ aut.name }}">{{ aut.name }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="gender">出版时间</label>
<input type="date" class="form-control item" id="gender" name="date">
</div>
<div class="form-group">
<label for="publish">出版社</label>
<select name="pub" class="form-control item" id="publish">
{% for pub in pubList %}
<option value="{{ pub.name }}">{{ pub.name }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="gender1">价格</label>
<input type="text" class="form-control item" id="gender1" name="price" placeholder="price">
</div>
<div class="pull-right"><a href="/shujichaxun/"><button type="button" class="btn btn-default" data-dismiss="modal">取消</button></a>
<input type="submit" value="提交" class="btn btn-primary"/>
</div>
</form>
{% endblock form %}

tianjia.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<h4>知道啥协议啊 ,你就同意...</h4>
</body>
</html>

xieyi.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css"/>
<script src="/static/jquery-3.2.1.js"></script>
<script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<style>
body {
background-color: #cccccc;
} .container {
margin-top: 150px; } </style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4"> <form class="form-horizontal" action="/xiugaimima/" method="post">
{% csrf_token %}
<h3 style="text-align: center">修改密码</h3>
<div class="form-group" style="margin-top: 30px">
<label for="inputEmail3" class="col-sm-3 control-label">原密码</label> <div class="col-sm-9" style="margin-left: -20px">
<input type="password" class="form-control" id="inputEmail3" placeholder="原密码" name="oldpwd">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-3 control-label">新密码</label> <div class="col-sm-9" style="margin-left: -20px">
<input type="password" class="form-control" id="inputPassword3" placeholder="新密码" name="newpwd">
</div>
</div>
<div class="form-group">
<label for="inputPassword4" class="col-sm-3 control-label">确认密码</label> <div class="col-sm-9" style="margin-left: -20px">
<input type="password" class="form-control" id="inputPassword4" placeholder="确认密码"
name="agapwd">
</div>
</div>
<div class="col-sm-10 col-sm-offset-2" style="color: red">{{ s }}</div>
<div class="form-group" style="margin-left: -40px">
<div class="col-sm-offset-3 col-sm-9">
<button type="submit" class="btn btn-primary">提交</button>
</div>
</div>
</form>
</div>
</div>
</div> </body>
</html>

xiugaimima.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css"/>
<script src="/static/jquery-3.2.1.js"></script>
<script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<style>
body {
background-color: #cccccc;
} .container {
margin-top: 150px; } </style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4"> <form action="/zhuce/" method="post">
{% csrf_token %}
<h3 style="text-align: center">请注册</h3>
<div class="form-group">
<label for="exampleInputEmail1">用户名</label>
<input type="text" class="form-control" id="exampleInputEmail1" placeholder="用户名" name="name">
</div>
<div class="form-group">
<label for="exampleInputPassword1">密码</label>
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="密码" name="password">
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="i1"> 我同意 <a href="/xieyi/">Cool公司注册协议</a>
</label>
</div>
<button type="submit" class="btn btn-primary disabled" id="i2">注册</button>
</form>
</div>
</div>
</div> <script>
{# 方式一 #}
$('#i1').on('change',function(){ {# 事件是 click 也可以 #}
$("#i2").toggleClass("disabled");
}) {# 方式二 #}
{#$('#aa').on('change',function(){#}
{# $("#btn").prop('disabled',!$(this).prop('checked'))#}
{# })#}
</script>
</body>
</html>

zhuce.html

{% extends 'base.html'%}
{% block tt %}
<div class="col-sm-9 col-md-10 main">
<div class="panel panel-primary">
<div class="panel-heading">作者信息</div>
<div class="panel-body">
<!-- Button trigger modal -->
<a href="/zuozhetianjia/"><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModal">
添加
</button></a> <table class="table table-hover">
{# <tr>#}
<thead>
<th>序号</th>
<th>姓名</th>
<th>性别</th>
<th>电话</th>
<th>地址</th>
</thead>
<tbody>
{% for auth in authlist %}
<tr>
<td>{{ forloop.counter }}</td>
<td>{{ auth.name }}</td>
<td>{{ auth.authdetail.sex }}</td>
<td>{{ auth.authdetail.tel }}</td>
<td>{{ auth.authdetail.addr }}</td> <td>
<div class="pull-left">
<a href="/zuozheshanchu/{{ pub.id }}">
<button class="btn btn-danger" >删除</button>
</a>
</div>
<a href="/zuozhebianji/?id={{ pub.id }}">
<button class="btn btn-success" style="margin-left: 5px">编辑</button>
</a>
</td>
</tr>
</tbody>
{% endfor %}
{% endblock tt %}

zuozhe.html

<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="/static/bootstrap-3.3.7/css/bootstrap.min.css"/>
<script src="/static/jquery-3.2.1.js"></script>
<script src="/static/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<style>
body {
background-color: #cccccc;
} .container {
margin-top: 150px; } </style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<form action="/login/" method="post">
{% csrf_token %}
<h3 style="text-align: center">请登录</h3>
<div class="form-group">
<label for="exampleInputEmail1" class="control-label">用户名</label>
<input type="text" class="form-control c1" id="exampleInputEmail1" name="name" placeholder="用户名">
{# <span class="help-block"></span>#}
</div>
<div class="form-group">
<label for="exampleInputPassword1" class="control-label">密码</label>
<input type="password" class="form-control c1" id="exampleInputPassword1" name="password" placeholder="密码">
{# <span class="help-block"></span>#}
</div>
<div style="color: red">{{ s }}</div>
<input class="btn btn-primary" type="submit" value="提交" id="sb"/>
<a href="/zhuce/"><input type="button" value="免费注册" class="btn btn-success pull-right"/></a>
<!--<button type="submit" class="btn btn-primary">Submit</button>-->
</form>
</div>
</div>
</div> {# 以下为jq代码 输入不能为空的提示 #} {#<script src="jquery-3.2.1.js"></script>#}
{# <script src="bootstrap-3.3.7/js/bootstrap.min.js"></script>#}
<!--<script src="abc.js">-->
{#<script>#}
{# $('.btn').on('click',function(){#}
{# $('form .form-group').removeClass('has-error');#}
{# $('form span').text('');#}
{# $('.c1').each(function(i,v){#}
{# if($(v).val().length===0){#}
{# $(v).parent().addClass('has-error');#}
{# console.log($(v).parent())#}
{# $(v).next().text($(v).prev().text()+'不能为空');#}
{# return false#}
{# }#}
{# })#}
{# })#} {#以下为jq自定义插件-输入不能为空#}
{#//$.kuozhan('#sb')#}
{#</script>#}
</body> </html>

登录校验.html

import pymysql

pymysql.install_as_MySQLdb()

__init__.py

"""
Django settings for xiangmu01 project. Generated by 'django-admin startproject' using Django 1.11.6. For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/ For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
""" import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '#^b0%&v92lkm34l)&yrw345gqdw^&w_zq$o0bja71uf40#qz=w' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app01',
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ROOT_URLCONF = 'xiangmu01.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 'xiangmu01.wsgi.application' # Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases # DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# } DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'xiangmu01', # 你的数据库名称
'USER': 'root', #你的数据库用户名
'PASSWORD': '963.', #你的数据库密码
'HOST': '', #你的数据库主机,留空默认为localhost
'PORT': '', #你的数据库端口
}
} # Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/ STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
] TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
'app01',
) LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.db.backends': {
'handlers': ['console'],
'propagate': True,
'level': 'DEBUG',
},
}
}

settings.py

"""xiangmu01 URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.11/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url
from django.contrib import admin
from app01 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^shujichaxun/', views.shujichaxun),
url(r'^chubanshechaxun/', views.chubanshechaxun),
url(r'^zuozhechaxun/', views.zuozhechaxun),
url(r'^shujishanchu/(\d+)', views.shujishanchu),
url(r'^shujitianjia/', views.shujitianjia),
url(r'^shujibianji/', views.shujibianji),
url(r'^login/', views.login),
url(r'^zhuce/', views.zhuce),
url(r'^middle/', views.middle),
url(r'^xieyi/', views.xieyi),
url(r'^xiugaimima/', views.xiugaimima),
url(r'^zhuxiao/', views.zhuxiao), ]

urls.py

bug:  注册的时候用户名一样的时候也可以注册   ///退出功能未实现   //分页盒子的布局

python-day73--django课上项目01的更多相关文章

  1. linux下配置python环境 django创建helloworld项目

    linux下配置python环境 1.linux下安装python3 a. 准备编译环境(环境如果不对的话,可能遇到各种问题,比如wget无法下载https链接的文件) yum groupinstal ...

  2. python框架Django实战商城项目之工程搭建

    项目说明 该电商项目类似于京东商城,主要模块有验证.用户.第三方登录.首页广告.商品.购物车.订单.支付以及后台管理系统. 项目开发模式采用前后端不分离的模式,为了提高搜索引擎排名,页面整体刷新采用j ...

  3. python框架Django实战商城项目之用户模块创建

    创建用户APP 整个项目会存在多个应用,需要存放在一个单独的文件包了,所以新建一个apps目录,管理所有子应用. 在apps包目录下穿件users应用 python ../../manage.py s ...

  4. Django 博客项目01 数据库设计与验证码校验+Ajax登录

    数据库设计 from django.db import models from django.contrib.auth.models import AbstractUser class UserInf ...

  5. Python和Django在Windows上的环境搭建

    作为一个.NET程序员,真心不喜欢Python以及PHP这种松散的语法.有人说,程序员应该多学几门语言,本想学习Java,无奈感觉Java的语法太啰嗦了.很多人都推荐Python,说它的语法简洁,执行 ...

  6. [Python] 建 Django 项目

    Python和Django的安装见这里:http://www.runoob.com/django/django-install.html 安装 Django 之后,您现在应该已经有了可用的管理工具 d ...

  7. Window环境下Python和Django的安装,以及项目的创建

    1.首先我们要下载python和Django,他们的下载地址如下 python地址:https://www.python.org/ Django地址:  https://www.djangoproje ...

  8. python三大主流web框架之Django安装、项目搭建

    这一篇我们将迎来python强大的web框架Django,相信大家都已经不陌生,本篇将介绍Django的安装及基础项目搭建,大神略过~ Django是需要我们手动pip安装的,首先我们来安装Djang ...

  9. python 的django项目复制方法

    python 的django项目复制方法 django_pyecharts_1修改为django_pyecharts_1_cs1.拷贝项目(确保原有项目是关闭状态下)2.粘贴项目并删除idea文件夹和 ...

随机推荐

  1. 在 2016 年学 JavaScript 是一种什么样的体验?(React从入门到放弃)

    jquery 年代 vs 前端模块化 http://blog.csdn.net/offbye/article/details/52793921 ++ 嘿,我最近接到一个 Web 项目,不过老实说,我这 ...

  2. UVA1025 城市里的间谍

    #include<iostream> #include<cstdio> #include<memory.h> using namespace std; #defin ...

  3. HDU 5452 Minimum Cut(LCA)

    http://acm.hdu.edu.cn/showproblem.php?pid=5452 题意: 有一个连通的图G,先给出图中的一棵生成树,然后接着给出图中剩余的边,现在要删除最少的边使得G不连通 ...

  4. Scala语言学习

    Scala的程序被编译成Java字节码(生成class文件),所以可以运行在JVM上,并且可以调用Java的类库,兼容Java程序. Scala 是一门多范式(multi-paradigm)的编程语言 ...

  5. ngui项目花屏问题

    项目用的ngui 最近在金立手机上遇到一个问题就是  启动的时候会花一下屏幕 一闪而过  由于ngui默认camera使用的是clear depth  所以按照网上的办法修改 color 跟skybo ...

  6. python中网络编程基础

    一:什么是c\s架构 1.c\s即client\server 客户端\服务端架构. 客户端因特定的请求而联系服务器并发送必要的数据等待服务器的回应最后完成请求 服务端:存在的意义就是等待客户端的请求, ...

  7. jsp技术和el表达式和jstl技术

    注:本文参考黑马视频的讲义 jsp技术 1.jsp脚本 )<%java代码%> ----- 内部的java代码翻译到service方法的内部 )<%=java变量或表达式> - ...

  8. IPC 之 Binder 初识

    概述 最近在看Android 的 IPC 机制,想要系统的研究一下,然后就走到了 Binder 这里,发现这个东西真是复杂,查看了一下些文章想要记录下.想要自己写但是发现一篇文章已经写的非常好了,就转 ...

  9. Spring分布式事务实现概览

    分布式事务,一直是实现分布式系统过程中最大的挑战.在只有单个数据源的单服务系统当中,只要这个数据源支持事务,例如大部分关系型数据库,和一些MQ服务,如activeMQ等,我们就可以很容易的实现事务. ...

  10. ArcFace Android 人脸检测与人脸识别集成分享

    目前我们的应用内使用了 ArcFace 的人脸检测功能,其他的我们并不了解,所以这里就和大家分享一下我们的集成过程和一些使用心得集成ArcFace FD 的集成过程非常简单在 ArcFace FD 的 ...