每当我按下我的提交按钮以使文件转到该文件页面时,我都会得到不允许的方法,我认为这是没有POST和GET的问题,但是我知道。基本上,这一行在我的代码中不起作用
if request.method == 'POST':
return redirect(url_for('files()'))
views.py
class HView(BaseView):
route_base = "/home"
@expose('/test')
@appbuilder.app.route('/test', methods=['GET', 'POST'])
def test(self):
if request.method == 'POST':
return redirect(url_for('files()'))
else:
return render_template(blah)
index.html
{% extends "appbuilder/base.html" %}
{% block title %}Title{% endblock %}
{% block content %}
<div class="container">
<div class="col-12-xs">
<h3>Bucket List</h3>
<table class="table table-striped">
<tr>
<th>Bucket Name</th>
<th>Created</th>
<th></th>
</tr>
{% for bucket in buckets %}
<tr>
<td>{{ bucket['Name'] }}</td>
<td>{{ bucket['CreationDate'] | datetimeformat }}</td>
<td>
<form class="select-bucket" action="{{ url_for('HView.test')}}" method="post">
<input type="hidden" name="bucket" value="{{ bucket['Name'] }}"/>
<button type="submit" class="btn btn-primary btn-sm">
<i class="fas fa-archive"></i>
</button>
</form>
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}
答案 0 :(得分:1)
尝试在@expose
例如:
class HView(BaseView):
route_base = "/home"
@expose('/test', methods=['GET', 'POST'])
def test(self):
if request.method == 'POST':
return redirect(url_for('files()'))
else:
return render_template(blah)