How to create Password Field in Model Django

Hemanth S R picture Hemanth S R · Jul 8, 2013 · Viewed 101k times · Source

I want to create password as password field in views.

models.py:

class User(models.Model):
    username = models.CharField(max_length=100)
    password = models.CharField(max_length=50)

forms.py:

class UserForm(ModelForm):
    class Meta:
        model = User

Answer

Akshar Raaj picture Akshar Raaj · Jul 8, 2013

Use widget as PasswordInput

from django import forms
class UserForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput)
    class Meta:
        model = User