Exemple #1
0
 def post(self, request):
     # 接收参数
     data = request.POST
     # 验证数据合法性
     form = UserForm(data)
     if form.is_valid():
         # 保存数据库
         user = User()
         user.phone = form.cleaned_data.get('phone')
         user.password = set_password(form.cleaned_data.get('password'))
         user.save()
         # 跳转到登录
         return redirect('blog:登录')
     else:
         return render(request, 'blog/reg.html', context=form.errors)
Exemple #2
0
def zhuce(request):
    if request.method == 'GET':
        rform = ZhuceForm()
        return render(request, 'zhuce.html', context={'rform': rform})
    else:
        rform = ZhuceForm(request.POST)
        if rform.is_valid():
            print(rform.cleaned_data)
            username = rform.cleaned_data.get('username')  # 从校验通过的数据中获取对应的参数值
            password = rform.cleaned_data.get('password')
            phone = rform.cleaned_data.get('phone')
            user = User()
            user.username = username
            user.password = password
            user.phone = phone
            user.save()
        else:
            return render(request, 'zhuce.html', context={'rform': rform})
        return HttpResponse('注册成功')
Exemple #3
0
def register(request):
    if request.method == 'POST':
        usr = User()
        usr.username = request.POST.get('username')
        # usr.password
        usr.set_password(request.POST.get('password'))
        usr.email = request.POST.get('email')
        usr.phone = request.POST.get('phone')
        usr.bio = request.POST.get('bio')
        usr.save()

        image_file = request.FILES.get('image')
        if image_file:
            img = ProfileImage()
            img.file = image_file
            img.alt_text = request.POST.get('alt_text', 'none')
            img.description = request.POST.get('img_desc', 'none')
            img.user = usr
            img.save()
        return redirect('login')

    return render(request, 'register.html')