django中的Form一般有两种功能:

  1、输入html

  2、验证用户输入

最简易的form验证:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .inline-group{
            position: relative;
            padding: 5px;
            width: 250px;
        }
        .input-group input{
            width: 200px;
            display: inline-block;

        }
        .inline-group span{
            display: inline-block;
            position: absolute;
            height: 12px;
            font-size: 8px;
            border: 1px solid darkorchid;
            background-color: chartreuse;
            color: aliceblue;
            top: 41px;
            left: 20px;
            width: 202px;
        }
    </style>
</head>
<body>

    <form action="form1/" method="POST">
        <div class="inline-group">

            {{ form.user }}    {#创建user的input标签#}

            {% if error.user.0 %}   {#如果出错误就把错误信息显示出来,否则隐藏#}
            <span>{{ error.user.0 }}</span>  {# 获得错误信息#}
            {% endif %}
        </div>
        <div class="inline-group">
            {{ form.pwd }}  {# 创建pwd的input标签#}
            {% if error.pwd.0 %}
            <span>{{ error.pwd.0 }}</span>
            {% endif %}
        </div>
        <div >
            <input type="submit" value="提交"/>
        </div>
    </form>

</body>
</html>
form.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
  • 2021-10-09
  • 2022-12-23
猜你喜欢
  • 2022-02-22
  • 2021-10-25
  • 2021-08-23
  • 2021-06-01
  • 2021-08-04
相关资源
相似解决方案