python  保障系统

from django.shortcuts import render,redirect,HttpResponse
from app01 import models
from django.forms import Form
from django.forms import fields
from utils.pager import PageInfo
# Create your views here. class Logins(Form):
# 定一个Form组件验证
user=fields.CharField( min_length=3,
strip=True,
required=True,
error_messages={
'min_length':'太短了',
'required':'不能为空',
}
)
pwd=fields.CharField(
min_length=5,
strip=True,
required=True,
error_messages={
'min_length': '太短了',
'required': '不能为空',
}
)

定义一个FORM验证

url视图函数

from django.conf.urls import url
from django.contrib import admin
from app01 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^login/', views.login),
url(r'^user_out/', views.user_out),
url(r'^registered/', views.registered),
url(r'^check_code/', views.check_code), url(r'^Avatars/', views.Avatars),
url(r'^bokes/(\w+).html$', views.bokes),
url(r'^boke/(?P<type_id>\d+)/', views.boke), url(r'^', views.boke), ]
from PIL import Image,ImageDraw,ImageFont,ImageFilter
import random
#导入生成随机字符的模块
def rd_check_code(width=120,height=30,char_length=5,font_file='kumo.ttf',font_size=28):
# 定义一个生成验证码的函数,宽120,高30是验证码的背景图大小,char_langth是在这个背景图上能写几个字符,file是设置显示在背景的字体样式,font_size是字体大小
code=[]
# 定义一个空列表
img=Image.new(mode='RGB',size=(width,height),color=(255,255,255))
#设置一个img背景图颜色是使用RGB,背景图的大小是120,30 颜色是用RGB的255,255,255
draw=ImageDraw.Draw(img,mode='RGB')
#创建一个画板,画板背景图是img,颜色采用RGB
def rndChar():
'''
生成随机字母
:return:
'''
return chr(random.randint(65,90))
#返回一个转成字符的字母(65,90之间在ascii码表是26个字母的大写)
def rndColor():
'''
生成随机颜色
:return:
'''
return (random.randint(0,255),random.randint(0,255),random.randint(0,255))
#返回一个组数字(由在ascii码表0,255对应的内容生成三个数字拼接) font=ImageFont.truetype(font_file,font_size)
# 创建一生成个文本的(font_file是文本字体的样式,font_size是文本字体的大小)
for i in range(char_length):
'''
生成字符(文字)
'''
# 循环在这个文本上最大能写几个字符总数
char=rndChar()
# 获取一个随机的字符
code.append(char)
# 追加到code列表中
h=random.randint(0,4)
# 从0之4之间生成随机的数字
draw.text([i * width / char_length , h], char,font=font,fill=rndColor())
#写文本(坐标1是每次循环的i数值乘以宽度的值在除以最大显示数值,h是从0之4生成的随机数字,组成---->0,h ---->24,h---->48,h---->120,h)
#设置font=font是默认自己选择的字体类型,fill是填充的颜色是执行随机颜色函数获取的随机颜色组 for i in range(5):
'''
生成干扰点
'''
draw.point([random.randint(0,width),random.randint(0,height)],fill=rndColor())
#画点坐标1是0和,120之间随机生成的数值,坐标2是0和30随机生成的数值,填充的颜色是执行随机颜色函数获取的随机颜色组 for i in range(5):
'''
生成干扰圆圈
'''
draw.point([random.randint(0,width),random.randint(0,height)],fill=rndColor())
#画点坐标1是0和,120之间随机生成的数值,坐标2是0和30随机生成的数值,填充的颜色是执行随机颜色函数获取的随机颜色组
x=random.randint(0,width)
# x=0到120之间随机生成的数字
y=random.randint(0,height)
# y=0到30之间随机生成的数字
draw.arc((x,y,x+4,y+4),0,90,fill=rndColor())
#设置圆存在的坐标和圆的坐标,设置角度的起始位置,设置角度的结束位置,填充的颜色是执行随机颜色函数获取的随机颜色组
for i in range(5):
'''
设置干扰的线
'''
x1=random.randint(0,width)
# x1=从0到120之间生成随机的数字
y1=random.randint(0,height)
# y1=从0到30之间生成随机的数字
x2 = random.randint(0, width)
# x2 = 从0到120之间生成随机的数字
y2 = random.randint(0, height)
# y2=从0到30之间生成随机的数字
draw.line((x1,y1,x2,y2),fill=rndColor())
#设置画线的起始坐标和结束坐标,填充的颜色是执行随机颜色函数获取的随机颜色组
img=img.filter(ImageFilter.EDGE_ENHANCE_MORE)
# 设置滤镜,让验证码的色差更加明显
return img,''.join(code)
#返回img整个画板,和拼接的随机字符(字符串类型)

封装的验证码

def check_code(request):
from io import BytesIO
from app01.check.check_code import rd_check_code
img,code=rd_check_code()
stream=BytesIO()
img.save(stream,'png')
request.session['yzm']=code
return HttpResponse(stream.getvalue())

验证调用函数

def login(request):
if request.method=='GET':
return render(request,'login.html')
else:
input_yzm=request.POST.get('yzm')
session_yzm=request.session.get('yzm')
if input_yzm.upper()==session_yzm.upper():
obj = Logins(request.POST)
if obj.is_valid():
users=models.UserInfo.objects.filter(username=obj.cleaned_data['user'],password=obj.cleaned_data['pwd']).first()
if users:
userss = models.UserInfo.objects.filter(username=obj.cleaned_data['user'], password=obj.cleaned_data['pwd']).values(
'avatar',
'username',
'blog__article__title',
'blog__article__comment',
'blog__article__summary',
'blog__article__comment_count',
'blog__article__up_count',
'blog__site',
)
print(userss[0]['avatar'])
request.session['users']={'users':obj.cleaned_data['user'],'touxiang':userss[0]['avatar'],'site':userss[0]['blog__site']}
article_list = models.UserInfo.objects.filter(username=obj.cleaned_data['user']).count()
page_info = PageInfo(request.GET.get('page'), article_list, 10, '/home.html', 11)
# print(page_info.start())
article_list = models.UserInfo.objects.filter(username=obj.cleaned_data['user'])[page_info.start():page_info.end()]
return redirect('/boke/')
# return render(request,'boke.html',{
# 'touxiang':userss[0]['avatar'],
# 'a_list':userss,
# 'article_list': article_list,
# 'page_info':page_info,
# 'zx':'注销',
# 'wdbok':'我的博客',
# })
return render(request, 'login.html', {'zhm': '账号或密码错误!'})
return render(request, 'login.html', {'obj':obj })
else:
return render(request,'login.html',{'msg':'验证码错误!'})

用户登录 views

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/static/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
<style>
.login{
width: 600px;
margin: 0 auto;
padding: 20px;
margin-top: 90px;
}
</style>
</head>
<body>
<div class="login">
<form class="form-horizontal" action="/login/" method="POST">
{% csrf_token %}
<div class="form-group">
<label class="col-sm-2 control-label">用户名</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="用户名" name="user">{{ obj.errors.user.0 }}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">密码</label>
<div class="col-sm-10">
<input type="password" class="form-control" placeholder="密码" name="pwd">{{ obj.errors.pwd.0 }}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">验证码</label>
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="验证码" name="yzm">
{{ msg }} </div>
<div class="col-sm-5">
<img style="width: 120px;height: 30px;" src="/check_code/">
&nbsp,&nbsp;
<a href="/login/">更换验证码</a>
</div>
</div> <div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<p><input type="checkbox" value="一个月免登录" name="jj">一个月免登录</p>
<input type="submit" class="btn btn-default" value="登录" />{{ zhm }}
</div> </div>
</form>
</div>
</body>
</html>

用户登录页面.html

def boke(request,*args, **kwargs):
# 获取当前URL
print(request.path_info)
condition = {}
a_list=models.Article.objects.all()
type_id = int(kwargs.get('type_id')) if kwargs.get('type_id') else None
if type_id:
a_list=models.Article.objects.filter(category=type_id)
condition['article_type_id'] = type_id
type_choice_list = models.Article.type_choices
article_list = models.Article.objects.filter(**condition).count()
page_info = PageInfo(request.GET.get('page'), article_list, 10, '/home.html', 11)
# print(page_info.start())
article_list = models.Article.objects.filter(**condition)[page_info.start():page_info.end()] return render(
request,
'boke.html',
{
'a_list':a_list,
'type_choice_list': type_choice_list,
'article_list': article_list,
'page_info':page_info,
'type_id': type_id,
'touxiang':'/static/8.png',
'users':'登录',
'zx':'注册',
'centen':'测试' }
)

用户主页面 views

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="/static/plugins/bootstrap-3.3.7-dist/css/bootstrap.css" />
<link rel="stylesheet" href="/static/plugins/font-awesome-4.7.0/css/font-awesome.css" />
<link rel="stylesheet" href="/static/css/commons.css"/>
<style>
.touxiang{
width:48px;
height: 48px;
border-radius: 50%;
}
</style>
</head>
<body>
{#<nav class="navbar navbar-default no-radius">#}
{# <div class="container">#}
{# <!-- 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 a1" href="#">老子的技术论坛</a>#}
{# </div>#}
{##}
{# <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">#}
{# <ul class="nav navbar-nav">#}
{# {% if type_id %}#}
{# <li><a class="a1" href="/">全部</a></li>#}
{# {% else %}#}
{# <li><a class="active" href="/">全部</a></li>#}
{# {% endif %}#}
{# {% for item in type_choice_list %}#}
{# {% if item.0 == type_id %}#}
{# <li class="active"><a class="a1" href="/boke/{{ item.0 }}/">{{ item.1 }}</a></li>#}
{# {% else %}#}
{# <li><a class="a1" href="/boke/{{ item.0 }}/">{{ item.1 }}</a></li>#}
{# {% endif %}#}
{# {% endfor %}#}
{# </ul>#}
{# {% if request.session.users %}#}
{# <ul class="nav navbar-nav navbar-right">#}
{# <li><a class="a1" href="/bokes/{{ request.session.users.site }}.html">我的博客</a></li>#}
{# <li><a class="a1" href="#">{{ request.session.users.users }}</a></li>#}
{# <li><a class="a1" href="/user_out/">注销</a></li>#}
{# <li><img class="touxiang" src="{{ request.session.users.touxiang }}"></li>#}
{# </ul>#}
{# {% else %}#}
{# <ul class="nav navbar-nav navbar-right">#}
{# <li><a class="a1" href="/login/"> 登录</a></li>#}
{# <li><a class="a1" href="/registered/">注册</a></li>#}
{# <li><img class="touxiang" src="{{ touxiang }}"></li>#}
{# </ul>#}
{# {% endif %}#}
{# </div>#}
{# </div>#}
{#</nav>#}
{#{% if centen == '测试' %}#}
{% if type_id %}
<nav class="navbar navbar-default no-radius">
<div class="container">
<!-- 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 a1" href="#">老子的技术论坛</a>
</div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
{% if type_id %}
<li><a class="a1" href="/">全部</a></li>
{% else %}
<li class="active"><a href="/">全部</a></li>
{% endif %}
{% for item in type_choice_list %}
{% if item.0 == type_id %}
<li class="active"><a class="a1" href="/boke/{{ item.0 }}/">{{ item.1 }}</a></li>
{% else %}
<li><a class="a1" href="/boke/{{ item.0 }}/">{{ item.1 }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% if request.session.users %}
<ul class="nav navbar-nav navbar-right">
<li><a class="a1" href="/bokes/{{ request.session.users.site }}.html">我的博客</a></li>
<li><a class="a1" href="#">{{ request.session.users.users }}</a></li>
<li><a class="a1" href="/user_out/">注销</a></li>
<li><img class="touxiang" src="{{ request.session.users.touxiang }}"></li>
</ul>
{% else %}
<ul class="nav navbar-nav navbar-right">
<li><a class="a1" href="/login/"> 登录</a></li>
<li><a class="a1" href="/registered/">注册</a></li>
<li><img class="touxiang" src="{{ touxiang }}"></li>
</ul>
{% endif %}
</div>
</div>
</nav>
<div>
<div class="container">
<div class="col-md-8">
<div class="article-list">
<div class="article-item">
{% for row in a_list %}
<div><a class="a1">{{ row.title }}</a></div>
<div class="art-body clearfix">
<a><img class="left a1" src="{{ row.blog.user.avatar }}"></a>
<a class="a1">{{ row.summary }}</a>
</div>
<a class="a1">
<p><i class="fa fa-user-o" aria-hidden="true"></i>
{{ row.blog.user.username }} 发布于 2017-07-10
<i class="fa fa-commenting-o" aria-hidden="true"></i>
{{ row.comment_count }}
<i class="fa fa-thumbs-o-up" aria-hidden="true"></i>
{{ row.up_count }}
</p> <hr style="border:0.5px dotted darkgray"/>
</a>
{% endfor %}
<nav aria-label="Page navigation">
<ul class="pagination">
{{ page_info.pager|safe }}
</ul>
</nav>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<p>人生若只如初见,何事秋风悲画扇</p>
<p>等闲变却故人心,却道故人心易变</p>
<p>骊山语罢清宵半,泪雨霖铃终不怨</p>
<p>何如薄幸锦衣郎,比翼连枝当日愿</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<p>十年生死两茫茫,不思量,自难忘</p>
<p>千里孤坟,无处话凄凉</p>
<p>纵使相逢应不识,尘满面,鬓如霜</p>
<p>夜来幽梦忽还乡,小轩窗,正梳妆</p>
<p>相顾无言,惟有泪千行</p>
<p>料得年年肠断处,明月夜,短松冈</p>
</div>
</div>
</div>
</div>
</div>
{% else %}
<nav class="navbar navbar-default no-radius">
<div class="container">
<!-- 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 a1" href="#">老子的技术论坛</a>
</div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
{% if type_id %}
<li><a class="a1" href="/">全部</a></li>
{% else %}
<li class="active"><a href="/">全部</a></li>
{% endif %}
{% for item in type_choice_list %}
{% if item.0 == type_id %}
<li class="active"><a class="a1" href="/boke/{{ item.0 }}/">{{ item.1 }}</a></li>
{% else %}
<li><a class="a1" href="/boke/{{ item.0 }}/">{{ item.1 }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% if request.session.users %}
<ul class="nav navbar-nav navbar-right">
<li><a class="a1" href="/bokes/{{ request.session.users.site }}.html">我的博客</a></li>
<li><a class="a1" href="#">{{ request.session.users.users }}</a></li>
<li><a class="a1" href="/user_out/">注销</a></li>
<li><img class="touxiang" src="{{ request.session.users.touxiang }}"></li>
</ul>
{% else %}
<ul class="nav navbar-nav navbar-right">
<li><a class="a1" href="/login/"> 登录</a></li>
<li><a class="a1" href="/registered/">注册</a></li>
<li><img class="touxiang" src="{{ touxiang }}"></li>
</ul>
{% endif %}
</div>
</div>
</nav>
<div>
<div class="container">
<div class="col-md-8">
<div class="article-list">
<div class="article-item">
{% for row in a_list %}
<div><a class="a1">{{ row.title }}</a></div>
<div class="art-body clearfix">
<a class="a1"><img class="left" src="{{ row.blog.user.avatar }}"></a>
<a class="a1">{{ row.summary }}</a>
</div>
<a class="a1">
<p><i class="fa fa-user-o" aria-hidden="true"></i>
{{ row.blog.user.username }} 发布于 2017-07-10
<i class="fa fa-commenting-o" aria-hidden="true"></i>
{{ row.comment_count }}
<i class="fa fa-thumbs-o-up" aria-hidden="true"></i>
{{ row.up_count }}
</p>
<hr style="border:0.5px dotted darkgray"/>
</a> {% endfor %}
<nav aria-label="Page navigation">
<ul class="pagination">
{{ page_info.pager|safe }}
</ul>
</nav>
</div>
</div>
</div>
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<p>人生若只如初见,何事秋风悲画扇</p>
<p>等闲变却故人心,却道故人心易变</p>
<p>骊山语罢清宵半,泪雨霖铃终不怨</p>
<p>何如薄幸锦衣郎,比翼连枝当日愿</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<p>十年生死两茫茫,不思量,自难忘</p>
<p>千里孤坟,无处话凄凉</p>
<p>纵使相逢应不识,尘满面,鬓如霜</p>
<p>夜来幽梦忽还乡,小轩窗,正梳妆</p>
<p>相顾无言,惟有泪千行</p>
<p>料得年年肠断处,明月夜,短松冈</p>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{#{% else %}#}
{# <div>#}
{# <div class="container">#}
{# <div class="col-md-8">#}
{# <div class="article-list">#}
{# <div class="article-item">#}
{# {% for row in a_list %}#}
{# <div><a class="a1">{{ row.blog__article__title }}</a></div>#}
{# <div class="art-body clearfix">#}
{# <a><img class="left a1" src="{{ row.avatar }}"></a>#}
{# <a class="a1">{{ row.blog__article__summary }}</a>#}
{# </div>#}
{# <a class="a1">#}
{# <p><i class="fa fa-user-o" aria-hidden="true"></i>#}
{# {{ row.username }} 发布于 2017-07-10#}
{# <i class="fa fa-commenting-o" aria-hidden="true"></i>#}
{# {{ row.blog__article__comment_count }}#}
{# <i class="fa fa-thumbs-o-up" aria-hidden="true"></i>#}
{# {{ row.blog__article__up_count }}#}
{# </p>#}
{##}
{# <hr style="border:0.5px dotted darkgray"/>#}
{# </a>#}
{# {% endfor %}#}
{# <nav aria-label="Page navigation">#}
{# <ul class="pagination">#}
{# {{ page_info.pager|safe }}#}
{# </ul>#}
{# </nav>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# <div class="col-md-4">#}
{# <div class="panel panel-default">#}
{# <div class="panel-heading">Panel heading without title</div>#}
{# <div class="panel-body">#}
{# <p>人生若只如初见,何事秋风悲画扇</p>#}
{# <p>等闲变却故人心,却道故人心易变</p>#}
{# <p>骊山语罢清宵半,泪雨霖铃终不怨</p>#}
{# <p>何如薄幸锦衣郎,比翼连枝当日愿</p>#}
{# </div>#}
{# </div>#}
{# <div class="panel panel-default">#}
{# <div class="panel-heading">Panel heading without title</div>#}
{# <div class="panel-body">#}
{# <p>十年生死两茫茫,不思量,自难忘</p>#}
{# <p>千里孤坟,无处话凄凉</p>#}
{# <p>纵使相逢应不识,尘满面,鬓如霜</p>#}
{# <p>夜来幽梦忽还乡,小轩窗,正梳妆</p>#}
{# <p>相顾无言,惟有泪千行</p>#}
{# <p>料得年年肠断处,明月夜,短松冈</p>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{# </div>#}
{#{% endif %}#}
</body>
</html>

用户主页面内容.html

用户注销函数

def user_out(request):
request.session.delete()
return redirect('/boke/')
import os
path_lis = []
def registered(request):
if request.method=='GET':
return render(request,'registered.html')
else:
if request.session.get('yzm').upper() == request.POST.get('yzm').upper():
obj = User_idne(request.POST)
if obj.is_valid():
dic = obj.cleaned_data.pop('pwds')
if dic==obj.cleaned_data['password']:
path_liss='\\'+ path_lis[-1]
print(path_liss)
obj.cleaned_data['avatar']=path_liss
models.UserInfo.objects.create(**obj.cleaned_data)
return redirect('/login/')
return render(request,'registered.html',{'mgs':'俩次密码不一致!'})
return render(request, 'registered.html', {'obj': obj})
return render(request, 'registered.html', {'msg':'验证码错误!'}) def Avatars(request):
path = request.FILES.get('fafafa')
paths = os.path.join('static', path.name)
print(paths)
path_lis.append(paths)
with open(paths, 'wb') as f:
for chunk in path.chunks():
f.write(chunk)
return HttpResponse(paths)

用户注册 views

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="/static/plugins/bootstrap-3.3.7-dist/css/bootstrap.css">
<style>
.login{
width: 600px;
margin: 0 auto;
padding: 20px;
margin-top: 90px;
}
.hide{
display: none;
}
img{
margin-top: -55px;
margin-left: 272px;
width: 80px;
height: 80px;
}
.files{
position: absolute;
left: 780px;
top: 440px;
}
.zhuce{
margin-top: 11px;
}
.imgs{
width: 120px;
height: 30px;
margin-left: 1px;
margin-top: 1px;
}
</style>
</head>
<body>
<div class="login">
<form id="f1" class="form-horizontal" method="POST" action="/registered/" enctype="multipart/form-data">
{% csrf_token %}
<div id="container3" class="imgs"></div>
<div class="form-group">
<label class="col-sm-2 control-label">用户名</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="用户名" name="username">{{ obj.errors.username.0 }}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">昵名</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="昵名" name="nickname">{{ obj.errors.nickname.0 }}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">邮箱</label>
<div class="col-sm-10">
<input type="text" class="form-control" placeholder="邮箱" name="email">{{ obj.errors.email.0 }}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">密码</label>
<div class="col-sm-10">
<input type="password" class="form-control" placeholder="密码" name="password">{{ obj.errors.password.0 }}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">确认密码</label>
<div class="col-sm-10">
<input type="password" class="form-control" placeholder="确认密码" name="pwds">{{ obj.errors.pwds.0 }}{{ mgs }}
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">验证码</label>
<div class="col-sm-5">
<input type="text" class="form-control" placeholder="验证码" name="yzm">
{{ msg }} </div>
<div class="col-sm-5">
<img style="width: 120px;height: 30px;" src="/check_code/" class="imgs">
&nbsp,&nbsp;
<a href="/registered/">更换验证码</a>
</div>
</div> <div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input type="button" onclick="zhuce()" class="btn btn-default zhuce" value="注册" />
</div> </div>
</form>
</div>
<div>
<form id="f2" class="form-horizontal" method="POST" action="/Avatars/" target="ifr" enctype="multipart/form-data">
{% csrf_token %}
<div>
<iframe class="hide" src="/Avatars/" name="ifr" id="ifr" frameborder=""></iframe>
<input type="file" name="fafafa" id="fafafa" class="files">
</div>
</form> </div>
<script src="/static/jquery-3.2.1.js"></script>
<script>
function zhuce() {
$('#f1').submit()
} $('#fafafa').change(function () {
document.getElementById('ifr').onload=Isitsgs;
$('#f2').submit()
}); function Isitsgs() {
var content =document.getElementById('ifr').contentWindow.document.body.innerText;
{#查找id是ifr的标签,的window内容的请求体的文本信息#}
var tag = document.createElement('img');
{#创建一个img标签并设置标签名字是tag#}
tag.src='/'+content;
{#找到名字是tag标签设置路径#}
$('#container3').append(tag);
{#找到id 是container3的标签添加一个名字是tag的标签tag#}
}
</script>
</body>
</html>

用户注册 html

def bokes(request,user):
if request.method=='GET':
userss = models.UserInfo.objects.filter(username=user,).values(
'avatar',
'username',
'blog__article__title',
'blog__article__comment',
'blog__article__summary',
'blog__article__comment_count',
'blog__article__up_count',
'blog__tag__title',
'blog__category__title',
'blog__tag__article2tag',
)
print(userss[0]['avatar'])
# request.session['centen']={'k':'v'}
article_list = models.UserInfo.objects.filter(username=user).count()
page_info = PageInfo(request.GET.get('page'), article_list, 10, '/home.html', 11)
# print(page_info.start())
article_list = models.UserInfo.objects.filter(username=user)[
page_info.start():page_info.end()]
# return redirect('/boke/')
print(userss[0]['blog__tag__article2tag'])
return render(request,'bokes.html',{
'touxiang':userss[0]['avatar'],
'a_list':userss,
'article_list': article_list,
'page_info':page_info,
'tag':userss[0]['blog__tag__title'],
# 'tag_count':userss[0]['blog'],
'category':userss[0]['blog__category__title'], })

用户个人主页 views

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" href="/static/plugins/bootstrap-3.3.7-dist/css/bootstrap.css" />
<link rel="stylesheet" href="/static/plugins/font-awesome-4.7.0/css/font-awesome.css" />
<link rel="stylesheet" href="/static/css/commons.css"/>
<style>
.touxiang{
width:48px;
height: 48px;
border-radius: 50%;
} .container{
width: auto;
height:auto;
}
</style>
</head>
<body>
<nav class="navbar navbar-default no-radius">
<div class="container">
<!-- 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 a1" href="#">老子的技术论坛</a>
</div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
{% if type_id %}
<li><a class="a1" href="/">全部</a></li>
{% else %}
<li><a class="active" href="/">全部</a></li>
{% endif %}
{% for item in type_choice_list %}
{% if item.0 == type_id %}
<li class="active"><a class="a1" href="/boke/{{ item.0 }}/">{{ item.1 }}</a></li>
{% else %}
<li><a class="a1" href="/boke/{{ item.0 }}/">{{ item.1 }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% if request.session.users %}
<ul class="nav navbar-nav navbar-right">
<li><a class="a1" href="/boke/{{ request.session.users.users }}.html">我的博客</a></li>
<li><a class="a1" href="#">{{ request.session.users.users }}</a></li>
<li><a class="a1" href="/user_out/">注销</a></li>
<li><img class="touxiang" src="{{ request.session.users.touxiang }}"></li>
</ul>
{% else %}
<ul class="nav navbar-nav navbar-right">
<li><a class="a1" href="/login/"> 登录</a></li>
<li><a class="a1" href="/registered/">注册</a></li>
<li><img class="touxiang" src="{{ touxiang }}"></li>
</ul>
{% endif %}
</div>
</div>
</nav>
<div> <div class="container">
<div class="col-md-2">
<ul>
<li>{{ tag }}{{ tag_count }}</li>
<li>{{ category }}</li>
</ul>
</div>
<div class="col-md-7">
<div class="article-list">
<div class="article-item">
{% for row in a_list %}
<div><a class="a1">{{ row.blog__article__title }}</a></div>
<div class="art-body clearfix">
<a><img class="left a1" src="{{ row.avatar }}"></a>
<a class="a1">{{ row.blog__article__summary }}</a>
</div>
<a class="a1">
<p><i class="fa fa-user-o" aria-hidden="true"></i>
{{ row.username }} 发布于 2017-07-10
<i class="fa fa-commenting-o" aria-hidden="true"></i>
{{ row.blog__article__comment_count }}
<i class="fa fa-thumbs-o-up" aria-hidden="true"></i>
{{ row.blog__article__up_count }}
</p> <hr style="border:0.5px dotted darkgray"/>
</a>
{% endfor %}
<nav aria-label="Page navigation">
<ul class="pagination">
{{ page_info.pager|safe }}
</ul>
</nav>
</div>
</div>
</div>
<div class="col-md-3">
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<p>人生若只如初见,何事秋风悲画扇</p>
<p>等闲变却故人心,却道故人心易变</p>
<p>骊山语罢清宵半,泪雨霖铃终不怨</p>
<p>何如薄幸锦衣郎,比翼连枝当日愿</p>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Panel heading without title</div>
<div class="panel-body">
<p>十年生死两茫茫,不思量,自难忘</p>
<p>千里孤坟,无处话凄凉</p>
<p>纵使相逢应不识,尘满面,鬓如霜</p>
<p>夜来幽梦忽还乡,小轩窗,正梳妆</p>
<p>相顾无言,惟有泪千行</p>
<p>料得年年肠断处,明月夜,短松冈</p>
</div>
</div>
</div>
</div>
</div>

用户个人主页.html

python 保障系统(一)的更多相关文章

  1. python 报障系统(完)

    python 报障系统(完) 一.报障系统原理: 原理: 1. 简单管理 2. 角色多管理(权限) a. 登录 session放置用户信息(检测是否已经登录) session放置权限信息(检测是否有权 ...

  2. Python云端系统开发入门——框架基础

    Django框架基础 这是我学习北京理工大学嵩天老师的<Python云端系统开发入门>课程的笔记,在此我特别感谢老师的精彩讲解和对我的引导. 1.Django简介与安装 Django是一个 ...

  3. Python云端系统开发入门 pycharm代码

    html <!DOCTYPE html><html><head> <meta charset="UTF-8"> <title& ...

  4. 【转】Python之系统交互(subprocess)

    [转]Python之系统交互(subprocess) 本节内容 os与commands模块 subprocess模块 subprocess.Popen类 总结 我们几乎可以在任何操作系统上通过命令行指 ...

  5. python获取系统内存占用信息的实例方法

    psutil是一个跨平台库(http://code.google.com/p/psutil/),能够轻松实现获取系统运行的进程和系统利用率(包括CPU.内存.磁盘.网络等)信息.它主要应用于系统监控, ...

  6. 举例讲解Linux系统下Python调用系统Shell的方法

    有时候难免需要直接调用Shell命令来完成一些比较简单的操作,比如mount一个文件系统之类的.那么我们使用Python如何调用Linux的Shell命令?下面来介绍几种常用的方法:1. os 模块 ...

  7. 一个简单的python选课系统

    下面介绍一下自己写的python程序,主要是的知识点为sys.os.json.pickle的模块应用,python程序包的的使用,以及关于类的使用. 下面是我的程序目录: bin是存放一些执行文件co ...

  8. Python之系统交互(subprocess)

    本节内容 os与commands模块 subprocess模块 subprocess.Popen类 总结 我们几乎可以在任何操作系统上通过命令行指令与操作系统进行交互,比如Linux平台下的shell ...

  9. python 选课系统

    couser.py: import sys,osBASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))sys.pa ...

随机推荐

  1. Java 中 利用正则表达式 获取 网页图片

    import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.net.URL;i ...

  2. 【Python】 uuid生成唯一ID

    uuid uuid是128位的全局唯一标识符(univeral unique identifier),通常用32位的一个字符串的形式来表现.有时也称guid(global unique identif ...

  3. zabbix自定义key监控mysql主从同步超简单!

    原理:利用在slave上运行show slave status获取Slave_IO_Running和Slave_SQL_Running的值 1.在zabbix客户端配置文件中加入: 首先要对mysql ...

  4. mysql-5.7.12安装

    CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载   # wget http://dev.mysql.com/get/mysql-communit ...

  5. 爬虫(BeautifulSoup--select--class的选择)

    <div class="item name" title="中央公园"> <a href="/Attraction_Review-g ...

  6. 2017年PHP程序员未来路在何方——韩天峰

    PHP 从诞生到现在已经有20多年历史,从Web时代兴起到移动互联网退潮,互联网领域各种编程语言和技术层出不穷, Node.js . GO . Python 不断地在挑战 PHP 的地位.这些技术的推 ...

  7. JavaScript(第七天)【对象和数组】

    什么是对象,其实就是一种类型,即引用类型.而对象的值就是引用类型的实例.在ECMAScript中引用类型是一种数据结构,用于将数据和功能组织在一起.它也常被称做为类,但ECMAScript中却没有这种 ...

  8. Win7(64Bit旗舰版) 安装 PL/SQL Developer图解说明

    Win7逐渐成为现行主流的windows操作系统,其32和64位系统平分秋色.然而当下还没有64位的PL/SQL Developer问世,直接用32位的PL/SQL Developer连接Win7(6 ...

  9. C语言程序设计(基础)- 第4周作业

    一.PTA作业 完成PTA第四周作业中8个题目,并将其中4个题目的思路列在博客中. 1.7-1 计算分段函数[1] 2.7-2 A除以B 3.7-6 阶梯电价 4.7-7 出租车计价 随笔具体书写内容 ...

  10. JAVA设计模式之【装饰者模式】

    JAVA设计模式之[装饰者模式] 装饰模式 对新房进行装修并没有改变房屋的本质,但它可以让房子变得更漂亮.更温馨.更实用. 在软件设计中,对已有对象(新房)的功能进行扩展(装修). 把通用功能封装在装 ...