Below is the code for the user registration. The password value is not saving to the auth_users table. I am using MySQL as my database.
Any help is highly appreciated TIA
class MyRegistrationForm(UserCreationForm):
email=forms.EmailField(required=True)
class Meta:
model=User
fields = ('username','email','password1','password2')
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.email=self.cleaned_data["email"]
if commit:
user.save()
return user
def register_user(request):
if request.method =='POST':
print request.POST['username']
print request.POST['password1']
print request.POST['password2']
form=MyRegistrationForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/register-success/')
args={}
args.update(csrf(request))
args['form']=MyRegistrationForm()
return render_to_response("register.html",args,
context_instance=RequestContext(request))
<form method="post" class="form-signin" action="/register/">{% csrf_token %}
<h2 class="form-signin-heading">Please sign in</h2>
<label for="users" class="sr-only">UserName</label>
<input name="username" type="text" id="users" class="form-control" placeholder="Username" required autofocus>
<label for="inputEmail" class="sr-only">Email address</label>
<input name="email" type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input name="password1" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<label for="inputPassword1" class="sr-only">Password</label>
<input name="password2" type="password" id="inputPassword1" class="form-control" placeholder="Password" required>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
You are calling super()
incorrectly. You need to use the form class MyRegistrationForm
, so that the save method of UserCreationForm
is called and sets the password.
user = super(MyRegistrationForm, self).save(commit=False)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments