Django学习笔记十七:添加签到功能

在..\templates\login_success.html中添加签到链接:

Django学习笔记十七:添加签到功能_第1张图片

在../templates中创建sign_index.html签到页面:




    {% load bootstrap3 %}      
    {% bootstrap_css %}        
    {% bootstrap_javascript%}  
    
    发布会管理


   
    

    
    




在../guest/urls.py中添加签到页面路由及签到动作路由:

Django学习笔记十七:添加签到功能_第2张图片

在../sign/views.py中添加签到页面及动作:

#签到页面
@login_required
def sign_index(request,eid):
    event = get_object_or_404(Event,id=eid)
    return render(request,"sign_index.html",{"event":event})

#签到动作
@login_required
def sign_index_action(request,eid):
    event = get_object_or_404(Event,id=eid)
    phone = request.POST.get("phone","")
    print(phone)
    result = Guest.objects.filter(phone=phone)
    if not result:
        return render(request,"sign_index.html",{"event":event,"hint":"手机号错误!"})
    result = Guest.objects.filter(phone=phone,event_id=eid)
    if not result:
        return render(request,"sign_index.html",{"event":event,"hint":"发布会id或者手机号错误!"})
    result = Guest.objects.get(phone=phone, event_id=eid)
    if result.sign:
        return render(request,"sign_index.html",{"event":event,"hint":"用户已签到!"})
    else:
        Guest.objects.filter(phone=phone,event_id=eid).update(sign="1")
        return render(request,"sign_index.html",{"event":event,"hint":"签到成功!","guest":result})


你可能感兴趣的:(Django)