0

I want to take the input from my /user/conference uri.

Here is my controller:

    @main.route('/user/conference', methods=["POST", "GET"])
    @login_required
    def user_search_conference():
        user = []
        conferences = []
        tags = []
        name = request.form.get('name')
        print(name)
        if name != "":
            user = db.session.query(UsersInfo).filter(
                UsersInfo.name == name).one()
            conferences = db.session.query(Conference).filter(
                Conference.creatoruser == user.authenticationid).all()
        else:
            conferences = db.session.query(Conference).all()
    
        return render_template('search_conference.html', conferences=conferences, len=len(conferences))

Here is my html form:

    <div>
            <form method="POST" action="/user/conference">
                <div class="field">
                    <div class="control">
                        <input class="input is-large" type="text" name="name" placeholder="Conference Host">
                    </div>
                </div>
    
                <button class="button is-block is-info is-large is-fullwidth">Search</button>
            </form>
        </div>

I added print for debugging and the name variable return None for that reason my databases cannot response. Why the form gives me None?

MacOS
  • 1,149
  • 1
  • 7
  • 14
Leo S
  • 319
  • 2
  • 16

1 Answers1

1

I think that your problem is here

<input class="input is-large" type="text" name="name" placeholder="Conference Host">

This is missing the id attribute. So change this line to

<input class="input is-large" type="text" name="name" id="name" placeholder="Conference Host">

And it should work.

The reason for this is that the attribute name is only used to identify the input field within the form filed, i.e. it is only on the browser side. But the id attribute is included in the request to the server. So you seem to have the same issue as this user.

MacOS
  • 1,149
  • 1
  • 7
  • 14