【问题标题】:How to catch errors from form in Django?如何从 Django 中的表单中捕获错误?
【发布时间】:2019-12-02 12:49:00
【问题描述】:

我有一个带有登录/注册表单的折叠 div。如果有错误,我如何捕捉并在页面上显示?

我的 html 表单:

 <form method="post" action="{% url 'login' %}">
 {% csrf_token %}
    <p><label for="id_username">Username:</label> <input 
    id="id_username" type="text" name="username" maxlength="30" /></p>
    <p><label for="id_password">Password:</label> <input 
    type="password" name="password" id="id_password" /></p>

    <input type="submit" value="Log in" />
    <input type="hidden" name="next" value="{{ request.get_full_path }}" 
    />
</form>

【问题讨论】:

标签: django django-forms


【解决方案1】:

Dude 使用内置登录,它为您提供密码加密。您使用的方法有点混乱,我建议使用 django 内置身份验证。这是链接,

https://simpleisbetterthancomplex.com/tutorial/2016/06/27/how-to-use-djangos-built-in-login-system.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 2018-05-15
    相关资源
    最近更新 更多