Reference Mushishi conference attendance system demo, combined with the knowledge their own, improved a bit. Only for learning purposes.
table of Contents
1, django profiles
2, log
3, page
4, the conference
5 guest list
1, django Overview
This picture shows the basic workflow django
Brief Description:
HTTP:: //127.0.0.1: user access via browser 8000 / index, first running a urlpatterns program, find the corresponding view function views.py by url routing, view All logic and data processing functions, and the user data to be processed after the function returns to the user's browser to see through the front index.html.
Detailed process flow:
2, Log
Back-end code
#登录逻辑处理函数
def login_action(request):
if request.method == "POST":
username = request.POST.get('username','')
password = request.POST.get('password','')
remember = request.POST.get('remember','')
print(remember,111)
#if username == 'admin' and password == '123456':
#django认证登录
user = auth.authenticate(username=username,password=password)
# print("user:%s"%user)
if user is not None:
auth.login(request,user) #登陆
#response.set_cookie('user',username,3600) #添加浏览器cookie
request.session['user'] = username #写入session 写入浏览器,存入服务器。
response = HttpResponseRedirect('/home/')
"""
重定向,先post→get通过路由urls,找到event_manager函数,跳转到找到event_manager.html页面。
"""
# 判断是否记住用户名
if remember == "on":
# 设置cookie username *过期时间为1周,按秒计算
response.set_cookie('username', username, max_age=7 * 24 * 3600)
return response
else:
# return render(request,'index.html',{'error':'username or password error!'})
return redirect('/login/')
#登录显示页面
def login(request):
'''显示登陆页面'''
# 获取cookie username
if 'username' in request.COOKIES:
username = request.COOKIES['username']
else:
username = ''
return render(request,'index.html',{'username': username})
Front-end code
#首页
<html>
<head>
{% load bootstrap3 %}
{% bootstrap_css %}
<link rel="stylesheet" href="/static/css/style.css">
</head>
<body style="margin: 5%;">
<div class="container">
<div class="form row">
<div class="form-horizontal col-md-offset-3" id="login_form">
<h3 class="form-title" style="padding-left: 20%"><font color="#fffaf0">欢迎登录</font></h3>
<div class="col-md-9">
<form action="/login_action/" method="post">
<div class="form-group">
<i class="fa fa-user fa-lg"></i>
<input class="form-control required" type="text" value="{{ username }}" placeholder="Username"
id="username" name="username" autofocus="autofocus" maxlength="20"/>
</div>
<div class="form-group">
<i class="fa fa-lock fa-lg"></i>
<input class="form-control required" type="password" placeholder="Password" id="password"
name="password" maxlength="8"/>
</div>
<div class="form-group">
<label class="checkbox">
{# <input type="checkbox" name="remember" value="1"/>记住我#}
<input type="checkbox" name="remember"/>记住我
</label>
<p>{{ back_dict }}</p>
</div>
<div class="form-group col-md-offset-9">
<button type="submit" class="btn btn-success pull-right" name="submit">登录</button>
</div>
</form>
</div>
</div>
</div>
</div>
</body>
</html>
Results are as follows
3. Home
Back-end code
#主页
def home(request):
return render(request,'home.html')
Results are as follows
3, conference
3, guest list
Three modules of code that are more, not one attached, such as the need to learn reference, please pay attention qq group: 696 400 122 and micro-channel public number: full-stack test development diary
and blog Park address: https: //home.cnblogs .com / u / liudinglong /