django web development conference attendance system

  introduction

  Recently learned conference attendance system demo Mushishi, combined with django their knowledge, to demo reshape a bit. But also to practice your hand, to consolidate the knowledge. Now share with you the results -

  Django workflow

  Learning django web development, first take a brief look at the working mechanism of django, see below:

 

 

Brief Description:
HTTP:: //127.0.0.1: user access through the browser 8000 / index, urlpatterns program is run first, the processing to find all logic and data corresponding to the views.py view function, the view through url routing function, and after the user data to be processed by the function index.html returned to the user's browser to see before.

 

  Details Process

   Access from the user data show → → processing functions through the browser, the whole forming a closed door.

  MVC is the well-known pattern, namely: the application into three components: Model (model), View (View), and a Controller (Controller). among them:

M-- state management applications (typically stored in the database), and bound to change state behavior (otherwise known as "business rules").

C-- receives an external operation by the user, according to the operation to obtain data access model, and calls the "View" display the data. The controller is the "model" and "View" isolation and become a link between the two.

After V-- responsible for formatting the data presented to the user.

  Django is a MVC framework. However, in Django, the controller accepts user input portion by the discretion of the frame (C delivered to the user), it is more concerned in Django model (the Model), the template (Template) and view (the Views), known as MTV mode:

 

M represents a model (Model), i.e., the data access layer. The layer of all transactions and data related to: how to access, how to verify the validity of the relationship between behavior and what data is contained and so on.

T represents the template (Template), ie, the presentation layer. This layer processing and performance-related decisions: how to display the page or other types of documents.

V represents a view (View), i.e., the business logic layer. The access layer includes associated logic model and retrieval of appropriate templates. You can think of it as a bridge between the model and template.

  登录

  后端代码:
#登录逻辑处理函数
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>
  效果如下

 

 

 

  首页

  后端代码
#主页
def home(request):
    return render(request,'home.html')

 

  效果如下

 

 

 

  发布会页面

 

 

 

  嘉宾页面

 

 

  总结

  由于自身工作繁忙,后端代码比较多点,不一一整理出来,如需学习,获取源码方式:加下面图中的QQ群,或关注csdn博客:https://blog.csdn.net/liudinglong1989

 

Guess you like

Origin www.cnblogs.com/liudinglong/p/12297244.html