'user'是此函数的无效关键字参数

时间:2017-07-16 09:19:50

标签: python django server

我正在使用自定义用户模型进行用户注册和登录功能。用户登录正确运行,但当我尝试注册用户时,它会引发我跟踪错误 enter image description here

在数据库中,此用户获得保存但在这里它会引发错误。

这是我的views.py文件

from django.shortcuts import render , render_to_response
from django.http import HttpResponseRedirect
from django.contrib import auth
from django.template.context_processors import csrf
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth import login, authenticate

# Create your views here.

def invalid_login (request):
    return render_to_response('invalid_login.html')

def register_user(request):
    if request.method=='POST':
        form=UserCreationForm(request.POST)
            if form.is_valid():
                form.save()
                username = form.cleaned_data.get('username')
                raw_password = form.cleaned_data.get('password1')
                user = authenticate(username=username, password=raw_password)
                login(request, user)
                #return render_to_response('register_success.html')
                return HttpResponseRedirect('/user_login/register_success')
            else:
                return HttpResponseRedirect('/user_login/invalid')


    args={}
    args.update(csrf(request))
    args['form']=UserCreationForm()
    return render_to_response('register.html' ,args)


def register_success(request):
    return render_to_response('register_success.html')

这是我的register.html文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<h2>Sign up</h2>
  <form method="post">
    {% csrf_token %}
    {{ form.as_p }}
    <button type="submit">Sign up</button>
  </form>

</body>
</html>

0 个答案:

没有答案