Password not saving to auth_user table in Django

user1844634

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

form.py

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

view.py

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))

HTML

  <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>
Alasdair

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to Encrypt Password before saving it to User Model Django?

django: User Registration with error: no such table: auth_user

Saving Hashed Version of User Password in Django Form Not Working

Django: How do I use is_active of auth_user table?

Django test user password

Error Key (user_id)=(1) is not present in table "auth_user" when migrating

Django form not saving password when creating user

merge django's auth_user with existing user table

Django Setup: No Such Table auth_user

How to add 'mobile' field to default auth_user table in User model in django?

Is it safe to share `auth_user` and `django_session` table for intranet Django projects?

Django superuser fixture error - no such table: auth_user

how to update django auth_user with queryset?

I'd like to get some data from auth_user table on Django

Graphite Web Error Log, OperationalError: no such table: auth_user

Django testing on separate database giving "OperationalError: no such table: auth_user"

Django saving in a model with User field

Django add field to auth_user

Creating a New Table (Model) and Relating it to auth_user in Django

Saving file with date and user django

Django.. I need to have a DateField which should be updated when auth_user table gets updated

MongoDB Invalid Email and Password when saving user

Django model saving on User login

Password not saving when creating user

resetting password of user django rest auth

Pass password in a hash table Django

Django deployment on heroku throws django.db.utils.OperationalError: no such table: auth_user

unable to create superuser in django getting error "django.db.utils.OperationalError: no such table: auth_user"

How to add columns to auth_user in django postgresql?