如何获取 django 的密码文本框?

发布于 2024-12-25 20:32:42 字数 383 浏览 2 评论 0原文

class Users(models.Model):
    username = models.CharField(max_length=255)
    password = models.CharField(max_length=300)
    password_token = models.CharField(max_length=300, default='0')

密码文本输入字段是常规文本输入字段。这不是密码字段。

如何在 django 中获取密码字段?

我尝试了 password = models.CharField(max_length=300, widget=forms.PasswordInput ) 但出现错误。

class Users(models.Model):
    username = models.CharField(max_length=255)
    password = models.CharField(max_length=300)
    password_token = models.CharField(max_length=300, default='0')

The password text input field is regular text input field. It's not password field.

How can I get password field in django?

I tried password = models.CharField(max_length=300, widget=forms.PasswordInput ) but got error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光病人 2025-01-01 20:32:42

如果您的应用程序中有 forms.py,一种方法是在您的 Meta 类中指定小部件,例如

from django.forms import ModelForm, PasswordInput
class UserForm(ModelForm):

    class Meta:
        model = Users

        widgets = {
            'password' : PasswordInput(),
        }

One way if you have a forms.py in your app is to specify the widgets in your class Meta e.g.

from django.forms import ModelForm, PasswordInput
class UserForm(ModelForm):

    class Meta:
        model = Users

        widgets = {
            'password' : PasswordInput(),
        }
流星番茄 2025-01-01 20:32:42

小部件在表单中分配,而不是在模型上分配。

请参阅表单文档的文档: https://docs.djangoproject.com/ en/dev/ref/forms/widgets/

Widgets are assigned in the forms, not on the model.

Please see the docs for forms documentation: https://docs.djangoproject.com/en/dev/ref/forms/widgets/

眼波传意 2025-01-01 20:32:42

您可以使用这种方法。在您的应用程序中创建一个名为 forms.py 的文件。

例如:

from django import forms
from models import Users

class UsersForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput)

    class Meta:
        model = Users

You can use this approach. Create a file named forms.py inside your app.

for example:

from django import forms
from models import Users

class UsersForm(forms.ModelForm):
    password = forms.CharField(widget=forms.PasswordInput)

    class Meta:
        model = Users
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文