# models.py
from django import models
class Student(models.Model):
username = models.CharField(max_length=60)
password = models.CharField(max_length=30)
# forms.py
from django import forms
class StudentForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = Student
In the above code snippet:
Note that we are using widget=forms.PasswordInput in forms.py not on models.py or views.py
You can also use the below code to make a model field password.
from django import forms
class StudentForm(forms.ModelForm):
class Meta:
model = Student
widgets = {
'password': forms.PasswordInput(),
}
# models.py
from django import models
class Employee(models.Model):
name = models.CharField(max_length=30)
password = models.CharField(max_length=20)
# forms.py
from django import forms
class EmployeeForm(forms.ModelForm):
password = forms.CharField(widget=forms.PasswordInput)
class Meta:
model = Employee
0 Comments