示例#1
0
def register(request):
    '''注册页面'''
    res = ""
    if request.method == "POST":
        username = request.POST.get('username')
        psw = request.POST.get('password')
        mail = request.POST.get('mail')

        # 先查询数据库是否有此用户名
        user_lst = User.objects.filter(user_name=username)
        if user_lst:
            # 如果已经注册过,就给个提示
            res = "%s用户已被注册" % username
            return render(request, 'register.html', {'rename': res})

        else:
            # 如果没被注册,插入数据库

            # 第一种写法 -- 推荐
            user = User()
            user.user_name = username
            user.psw = psw
            user.mail = mail
            user.save()

            # 第二种写法
            # user = User(user_name=username,
            #            psw = psw,
            #            mail = mail,
            #            )
            # user.save()
            return render(request, 'login.html', {'rename': res})
    return render(request, 'register.html')
示例#2
0
def register(request):
    """注册页面"""
    res = ''
    if request.method == 'POST':
        username = request.POST.get('username')
        psw = request.POST.get('password')
        mail = request.POST.get('mail')

        # 查询数据库中是否由此用户名
        user_list = User.objects.filter(user_name=username)
        if user_list:
            # 如果已经注册给提示
            res = '{}用户已经被注册!'.format(username)
            return render(request, 'register.html', {'rename': res})
        else:
            # 如果没有注册过,进行注册
            # 第一种写法 (建议)
            user_new = User()
            user_new.user_name = username
            # 加密方法
            user_new.psw = make_password(psw)
            user_new.mail = mail
            user_new.save()

            # 第二种写法
            # user_new = User(user_name=username,
            #                 psw=psw,
            #                 mail=mail)
            # user_new.save()

            return render(request, 'login.html', {'rename': res})

    return render(request, 'register.html')
示例#3
0
def Add_user(request):
    global count
    count += 1
    user = User()
    user.user_age = count
    user.user_name = random.choice(['Wang', 'Chan', 'Liu', 'Lin'])
    user.user_gender = not random.getrandbits(1)
    user.save()

    return render(request, ('add_user.html'))
示例#4
0
def register(request):
    message = ''

    if request.method == 'POST':
        form = InputForm(request.POST)
        if form.is_valid():
            user_name = request.POST.get('user_name')
            passwd = request.POST.get('passwd')

            try:
                user = User()
                user.user_name = user_name
                user.passwd = passwd
                user.save()
                message = user_name + "ようこそ!"

            except:
                message = 'すでに同じユーザ名が存在します'
        else:
            message = 'エラー'
    else:
        form = InputForm()

    return render(request, "register.html", {'form': form, 'message': message})