【问题标题】:How can you edit the form field for django.contrib.auth cosmestically?如何从外观上编辑 django.contrib.auth 的表单域?
【发布时间】:2015-12-10 19:51:37
【问题描述】:

我目前正在做 django-registration 应用程序,它使用标准的 Django.contrib.auth 模型来登录和注销用户。当您呈现登录页面时,它会显示字段标签和字段:

Username: [username field]
Password: [password]

Log in [button]

从风格上讲,我想删除标签并将“用户名”和密码作为占位符放入。它看起来像

[Enter Username]
[Enter Password]

Log in [button]

国内有没有不重写django.contrib.auth登录流程的方法?

【问题讨论】:

    标签: django django-forms django-registration django-contrib


    【解决方案1】:

    一种简单的方法是重写登录表单。假设您的 urlconf 如下所示:

    urlpatterns = [
    url(r'^login/$', 'django.contrib.auth.views.login', {'template_name': 'login.html'},
        name='login'),
    

    ]

    现在根据您的需要在project/templates/login.html创建登录表单 根据您的模板设置将 login.html 放入 settings.py

    检查official docsherehere 中的示例

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多