如何在 Django 中创建密码输入字段 [英] How to create password input field in django

查看:22
本文介绍了如何在 Django 中创建密码输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有一些字段和密码字段的 django 模型类.我想显示密码输入,而不是显示常规的纯文本.我创建了一个这样的模型类:

Hi I am using the django model class with some field and a password field. Instead of displaying regular plain text I want to display password input. I created a model class like this:

class UserForm(ModelForm):
    class Meta:
        password = forms.CharField(widget=forms.PasswordInput)
        model = User
        widgets = {
            'password': forms.PasswordInput(),
        }

但我收到以下错误:NameError: name 'forms' is not defined.

But i am getting the following error: NameError: name 'forms' is not defined.

我使用的是 Django 1.4.0 版.我点击了这个链接:Django 密码问题

I am using django version 1.4.0. I followed this link : Django password problems

仍然出现相同的错误.我该怎么办.我哪里出错了.请帮忙

Still getting the same error. What should i do. Where am i getting wrong.Please help

推荐答案

您需要在导入中包含以下内容;

You need to include the following in your imports;

from django import forms

这篇关于如何在 Django 中创建密码输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆