Python django框架开发发布会签到系统(web开发)

参考虫师的发布会签到系统demo,自己结合所学知识,改良了一下。仅供学习用途。

目录

1、django概况
2、登录
3、主页
4、发布会
5、嘉宾列表

1、django概况

这张图为django基本的工作流
在这里插入图片描述
简单说明:
用户通过浏览器访问:http://127.0.0.1:8000/index,首先运行的是urlpatterns程序,通过url路由找到对应的视图函数views.py,视图函数处理所有逻辑和数据,并且将用户要的数据经过函数处理后通过index.html返回给浏览器前的用户看。

详细的处理流程:
在这里插入图片描述

2、登录

后端代码

#登录逻辑处理函数
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})

前端代码

#首页
<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>

效果如下

在这里插入图片描述

3、主页

后端代码

#主页
def home(request):
    return render(request,'home.html')

效果如下
在这里插入图片描述

3、发布会
在这里插入图片描述

3、嘉宾列表
在这里插入图片描述

三个模块的代码比较多,就不一一附上了,如需要学习参考,请关注qq群:696400122及微信公众号:全栈测试开发日记,
以及博客园地址:https://home.cnblogs.com/u/liudinglong/

发布了82 篇原创文章 · 获赞 43 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/liudinglong1989/article/details/104269841
今日推荐