Theo
Theo

Reputation: 71

Method not allowed Flask

Whenever I press my submit button for my file to go to that file page I get a method not allowed, I thought it was an issue with not has POST and GET but I do. Essentially this line isn't working in my code

     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 %}

Upvotes: 0

Views: 164

Answers (1)

Rakesh
Rakesh

Reputation: 82765

Try specifying the method in @expose

Ex:

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)

Upvotes: 1

Related Questions