我在模态框中设置了一个表单,使用 POST 提交,遇到的问题是提交后收不到表单数据,第一次在模态框中写表单,求教是哪里的问题。
模态框代码:
<!-- 模态框( Modal ) -->
<form action="{{ url_for('dashboard.freeze_user') }}" method="POST">
<div class="modal fade" id="freeze_users" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title -align-center" id="myModalLabel">确定冻结该账户?</h4>
</div>
<div class="modal-body">
<input type="username" name="user" id="user" value="" disabled="disabled">
<input type="submit" class="btn btn-danger" value="确认">
<button type="button" class="btn btn-dark" data-dismiss="modal">关闭</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal -->
</div>
</form>
后端代码:
@dashboard_bp.route('/api/users/freeze', methods=['POST'])
@admins_only
def freeze_user():
user = request.form.get("user")
print(request.data)
print(user)
# if user:
# print(user)
return redirect(url_for('dashboard.users_info'))
打印信息:
127.0.0.1 - - [03/May/2020 19:29:34] "GET /usersinfo HTTP/1.1" 200 -
127.0.0.1 - - [03/May/2020 19:29:38] "POST /api/users/freeze HTTP/1.1" 302 -
b''
None
127.0.0.1 - - [03/May/2020 19:29:38] "GET /usersinfo HTTP/1.1" 200 -
1
fy1993 2020-05-03 21:36:21 +08:00 1
input 框设置为 disabled 对应的数据 是不会提交后台的
|
2
llllllLllll OP @fy1993 #1 谢谢
|