为什么我使用 enctype='application/json' 但 CONTENT_TYPE 仍然是 application/x-www-form-urlencoded

问题描述 投票:0回答:1
<form enctype='application/json' action="{% url 'xxx'  %}" method="post">
    {% csrf_token %}
    <input type='number' name='bottle-on-wall' value='1'>
    <input type='number' name='bottle-on-wall' value='2'>
    <input type='number' name='bottle-on-wall' value='3'>
    <button type="submit">send</button>
</form>

CONTENT_TYPE   'application/x-www-form-urlencoded'

如何将表单数据以 json 形式发送到服务器

json django forms templates post
1个回答
0
投票

使用

multipart/form-data

<form enctype='multipart/form-data' action="{% url 'xxx'  %}" method="post">
    {% csrf_token %}
    <input type='number' name='bottle-on-wall' value='1'>
    <input type='number' name='bottle-on-wall' value='2'>
    <input type='number' name='bottle-on-wall' value='3'>
    <button type="submit">send</button>
</form>
© www.soinside.com 2019 - 2024. All rights reserved.