0

The following question provides background for this question

I am posting form data to a Flask URL. The HTML form looks like so.

{% extends "AdminMaster.html" %} {% block title %}Create New Application{% endblock %} {% block page %}Create New Application{% endblock %} {% block head %} {{ super() }} {% endblock %} {% block content %}
<div class="container">
  <div class="page-header">
    <h1>Create a new Application</h1>
  </div>
  <form action="/xxxx/xdf">
    <div class="form-group">
      <label for="txtApplicationName">Application Name</label>
      <input type="text" class="form-control" id="txtApplicationName" placeholder="Application Name">
    </div>
    <div class="form-group">
      <label for="txtApplicationCategoryName">Application Category Name</label>
      <input type="text" class="form-control" id="txtApplicationCategoryName" placeholder="Application Category">
    </div>
    <button type="submit" class="btn btn-primary">
      Add New Category
    </button>
  </form>
</div>
{% endblock %}

I have the following Flask route to handle the post.

@admin_routes.route('/xxxx/xdf', methods=['GET', 'POST'])
@authenticate_admin
def create_new_application():
    app_name = request.args[0]
    return redirect('/xxxx')

The problem is everytime I make a post I get the 400 Bad Request. I am not sure why ?

enter image description here

Vinay Joseph
  • 5,515
  • 10
  • 54
  • 94

1 Answers1

1

request.args is a MultiDict. It is not a sequence. You access its elements with keys, not indexes.

request.args['some_name']

Here 'some_name' matches the name attribute of a form element.

<input type="text" name="some_name">

Without providing the name attribute, the browser won't include the field in the http GET or POST request.

      <input type="text" name="????" class="form-control" id="txtApplicationCategoryName" placeholder="Application Category">
dirn
  • 19,454
  • 5
  • 69
  • 74