Beispiel #1
0
def register(request):
    reg_form = RegForm()
    if request.method == "POST":
        reg_form = RegForm(request.POST, request.FILES)
        if reg_form.is_valid():
            # 注册成功,跳转到登录页面
            print(request.POST)
            print(reg_form.cleaned_data)
            reg_form.cleaned_data.pop('re_pwd')
            models.User.objects.create(**reg_form.cleaned_data)
            return redirect("login")
    return render(request, "register.html", {'reg_form': reg_form})
Beispiel #2
0
def register2(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():  # 是不是一个合格的数据返回bool值
            # cleaned_data 是经过检验的数据
            print(form_obj.cleaned_data)
            # 去数据库操作
            return HttpResponse('Register is success!')
        # else:
        #     return HttpResponse('Fail')
    return render(request, 'register2.html', {'form_obj': form_obj})
Beispiel #3
0
def reg(request):
    form_obj = RegForm()
    if request.method == "POST":
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # 校验成功,去注册
            print(form_obj.cleaned_data)
            # User.objects.create(username=form_obj.cleaned_data.get("username"),password=)
            # 把re_pwd从 cleaned_data中移除
            form_obj.cleaned_data.pop("re_password")
            User.objects.create_user(**form_obj.cleaned_data)  # ?
            # models.UserInfo.objects.create_user(**form_obj.cleaned_data)

            return HttpResponse("OK")
    return render(request, "reg.html", {"form_obj": form_obj})
Beispiel #4
0
def register2(request):
    form_obj = RegForm()
    # print(RegForm.hobby.choices)
    # print(11,form_obj.fields['hobby'].choices)

    if request.method == 'POST':
        form_obj = RegForm(request.POST)

        if form_obj.is_valid():
            # cleaned_data  是经过校验的数据
            print(form_obj.cleaned_data)
            # 数据操作
            return HttpResponse('注册成功')

    return render(request, 'register2.html', {"form_obj": form_obj})
Beispiel #5
0
def register2(request):
    form_obj = RegForm()
    if request.method == "POST":
        # 实例化form对象的时候,把post提交过来的数据直接传进去
        form_obj = RegForm(request.POST)
        # 调用form_obj校验数据的方法
        if form_obj.is_valid():
            # form_obj.cleaned_data  # 所有经过校验的数据
            # models.UserInfo.objects.create(
            #     name=request.POST.get("name"),
            #     pwd=request.POST.get("pwd")
            # )
            # # 等价于上面的创建记录的操作
            # models.UserInfo.objects.create(**form_obj.cleaned_data)
            return HttpResponse("登陆成功")
    return render(request, "register2.html", {"form_obj": form_obj})
Beispiel #6
0
def reg(request):
    form_obj = RegForm()

    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # 数据库操作
            # username = form_obj.cleaned_data.get('username')
            # password = form_obj.cleaned_data.get('password')

            # User.objects.create(username=username,password=password)

            form_obj.cleaned_data.pop('re_password')
            # User.objects.create_user(is_staff=1, **form_obj.cleaned_data)

            # 创建超级用户
            User.objects.create_superuser(email='', **form_obj.cleaned_data)

            return redirect('/login/')

    return render(request, 'reg.html', {'form_obj': form_obj})
Beispiel #7
0
def register(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST, request.FILES)
        if form_obj.is_valid():
            # form_obj.cleaned_data.pop('re_password')
            # models.User.objects.create(**form_obj.cleaned_data)
            form_obj.save()
            return redirect('login')
    return render(request, 'register.html', {'form_obj': form_obj})
Beispiel #8
0
def register(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST, request.FILES)
        if form_obj.is_valid():
            # 注册成功

            form_obj.save()
            return redirect('login')

    return render(request, 'register.html', {'form_obj': form_obj})
Beispiel #9
0
def register(request):
    form_obj = RegForm()
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        if form_obj.is_valid():
            # 注册成功
            # models.User.objects.create()
            form_obj.save()
            return redirect('login')

    return render(request, 'register.html', {'form_obj': form_obj})
Beispiel #10
0
def reg(request):
    """
    注册页面
    :param request:
    :return:
    """

    if request.method == "GET":
        form_obj = RegForm(request)
        return render(request, "reg.html", {"form_obj": form_obj})
    else:
        response_dict = {"user": None, "error_msg": None}
        print("hello")
        form_obj = RegForm(request, data=request.POST)
        print(request.POST)
        if not form_obj.is_valid():
            response_dict["error_msg"] = form_obj.errors
        else:
            name = form_obj.cleaned_data.get("username")
            pwd = form_obj.cleaned_data.get("password")
            email = form_obj.cleaned_data.get("email")
            avatar_img = request.FILES.get("avatar_img")
            if not avatar_img:
                user_obj = models.UserInfo.objects.create_user(username=name,
                                                               password=pwd,
                                                               email=email,
                                                               nickname=name)
            else:
                user_obj = models.UserInfo.objects.create_user(
                    username=name,
                    password=pwd,
                    email=email,
                    nickname=name,
                    avatar=avatar_img)
            print(user_obj.avatar, "---")
            response_dict["user"] = user_obj.nickname
        print(response_dict)
        return HttpResponse(json.dumps(response_dict))
Beispiel #11
0
def register(request):
    form_ojb = RegForm()
    if request.method == 'POST':
        form_ojb = RegForm(request.POST, request.FILES)
        if form_ojb.is_valid():
            # 注册成功
            # print(request.POST)
            # print(form_ojb.cleaned_data)

            # form_ojb.cleaned_data.pop('re_pwd')
            # models.User.objects.create(**form_ojb.cleaned_data)#  **打散
            form_ojb.save()
            return redirect('login')
    return render(request, 'regeister.html', {'form_ojb': form_ojb})
Beispiel #12
0
def reg(request):
    # 判断请求方式
    if request.method == 'POST':
        form_obj = RegForm(request.POST)
        print(request.POST)
        # 对数据进行校验
        if form_obj.is_valid():
            print('111')
            print('hao l ldfdf ')
            # 数据正确 插入数据库
            print(form_obj.cleaned_data)
            form_obj.save()
            return redirect(reverse('login'))
        else:
            print(form_obj.errors)

    else:
        form_obj = RegForm()

    return render(request, 'reg.html', {'form_obj': form_obj})
Beispiel #13
0
def reg(request):
    if request.method == "POST":
        form = RegForm(data=request.POST, files=request.FILES)
        reg_dic = {"flag": False, "error": None}
        if form.is_valid():
            reg_dic['flag'] = True
            avatar = request.FILES.get('avatar')
            print("---------------", avatar)
            if avatar:
                form.cleaned_data['avatar'] = avatar
            else:
                form.cleaned_data['avatar'] = "avatar/default.png"
            confirmPassword = form.cleaned_data.pop('confirmPassword')
            print(form.cleaned_data)
            models.Userinfo.objects.create_user(**form.cleaned_data)
        reg_dic['error'] = form.errors
        print(reg_dic)
        return HttpResponse(json.dumps(reg_dic))

    form = RegForm()
    return render(request, 'reg.html', {'form': form})