首页 > 解决方案 > 如何使用 Django 中的表单在视图中发布运行时数据

问题描述

我使用ajax在特定的div部分写入数据,现在我想在views.py中发布这些数据,但它返回None。<input type='checkbox' id='filesid' name = 'filesname' value='abc'>当我像abc一样手动写作时。它返回值。jquery 也适用于此。html代码

html_code = "<input type='checkbox' id='filesid' name = 'filesname' value='"+i+"'>"+i+"<br>"

$('#runtime-div').html(html_code);

另一个使用表单的 html 页面

<form  action = '/home/update_file/' id="UpdateDataFiles" method="post" enctype="multipart/form-data" onsubmit="return myUpdateFile()">
    {% csrf_token %}
    <div id='runtime-div' class="card-body">

    </div>
</form>

视图.py

filename = request.POST.get('filesname')
print(filename)

标签: javascriptjquerydjango

解决方案


推荐阅读