(Python) Flask - request.args.get returning NoneType (Python) Flask - request.args.get returning NoneType flask flask

(Python) Flask - request.args.get returning NoneType


request.args holds the values in the query string. Your form on the other hand is sending values in the POST body.

Use the request.form mapping instead, or use request.values, which combines request.form and request.args.

Alternatively, change your form method to GET to have the browser put the arguments in the query string instead.


This is a really bad idea.

if not request.args.get("n"):                   raise RuntimeError("missing n")    if not request.args.get("s"):        raise RuntimeError("missing n")

First of all, using the .get() function will return None if the value isn't set, in turn not giving an index error like getting a list index would.

If you are hell bent on returning an error, you're better of giving a ValueError.

Otherwise, I'd be doing (and probably should anyway) client side form validation with javascript, it could just be making sure that the inputs aren't empty with a required attribute.

Also, try naming your name="" more accurately, instead of using n for name, actually use name, it just makes everything far easier to understand developing it.


Try this:

request.get_data()

It returns dictionary object.