Reputation: 391
I am new to Django and I want to make a user registration form in Django. While creating model, I gave a fieldtype->PasswordField() to password field but when I run this model into terminal I got a error
password=models.PasswordField()
AttributeError: 'module' object has no attribute 'PasswordField'
So I want to know that which field type is used for password in Django.I already refer to form doc but I found nothing.
so please help me
Upvotes: 1
Views: 1426
Reputation: 53376
There is no PasswordField()
in django. You can to use CharField()
to store a password, but to show it as password input type in a html form you can specify a widget to it.
Example:
password = forms.CharField(widget=forms.PasswordInput())
More reference at :PasswordInput
Upvotes: 2
Reputation: 33420
Use django.db.models.CharField, since this is an OK database column type for a password string
Use django.forms.PasswordWidget, to represent this field in a form, see overriding default form field widgets
models.py:
from django.db import models
class YourModel(models.Model):
password = models.CharField(max_length=200)
forms.py:
from django import forms
from models import YourModel
class YourModelForm(forms.ModelForm):
class Meta:
widgets = {'password': forms.PasswordField}
model = YourModel
Upvotes: 4