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

2
  • Can you share the traceback that is leading to the bad request? Commented Aug 10, 2015 at 12:25
  • Just added the stack trace. Commented Aug 10, 2015 at 12:38

1 Answer 1

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">
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks so the form is submitting, but I am still getting the 400
I have just added the stack trace to the question. Thanks
That's logging information, not the traceback. Please share the full traceback as well as line 812 from module.py.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.