Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何通过表单HTML发布数据?_Python_Html_Django_Forms_Http Post - Fatal编程技术网

Python 如何通过表单HTML发布数据?

Python 如何通过表单HTML发布数据?,python,html,django,forms,http-post,Python,Html,Django,Forms,Http Post,我想通过表单将数据发布到服务器。我该怎么做 <div class="panel-body"> <form role="form" action="{% url 'login' %}" method="POST"> {% csrf_token %} <div class="form-group"> <label for="sender-email" class="control-label"&

我想通过表单将数据发布到服务器。我该怎么做

<div class="panel-body">
    <form role="form" action="{% url 'login' %}" method="POST">
        {% csrf_token %}
        <div class="form-group">
            <label for="sender-email" class="control-label">Username:</label>
            <div class="input-icon"> <i class="icon-user fa"></i>
                <input id="sender-email" type="text" placeholder="Username" class="form-control email">
            </div>
        </div>
        <div class="form-group">
            <label for="user-pass" class="control-label">Password:</label>
            <div class="input-icon"> <i class="icon-lock fa"></i>
                <input type="password" class="form-control" placeholder="Password" id="user-pass">
            </div>
        </div>
        <div class="form-group">
            <input class="btn btn-primary btn-block" id="authenticate_user" type="submit" value="Submit">
        </div>
    </form>
</div>

如何在不使用jquery的情况下发布数据?我知道一种通过AJAX jquery发布的方法,但我不想这样做。

使用输入元素的
name
属性填充发布数据。更改您的
id
属性或相应地添加一个
名称。例如:

<input type="password" class="form-control" placeholder="Password" name="user-pass">


你也应该考虑使用A来更容易地处理你的数据。

< P>输入标签的<代码>名称'< /代码>属性被设置为<代码>请求的键。获得< /代码>和<代码>请求。POST < /C> > /P> 将name属性添加到所有输入标记

<input name="username" id="sender-email" type="text" placeholder="Username" class="form-control email">

<input name="password" type="password" class="form-control" placeholder="Password" id="user-pass" >


为什么在模板中使用{%csrf_token%}而在视图中使用@csrf_emption?“Django使用输入标记的'name'属性作为request.GET和request.POST的键”:这与Django无关,这是HTML规范。@brunodesthuilliers是的,我知道。但是陈述一个具体的案例并不意味着泛型就不同了。我理解,尽管这可能会造成混乱/传授一半知识。于是编辑了这篇文章。
<input name="username" id="sender-email" type="text" placeholder="Username" class="form-control email">

<input name="password" type="password" class="form-control" placeholder="Password" id="user-pass" >