-1

I'm running into some difficulties executing Flask code.

I have an HTML form which looks like this:

<form action="index">
    <input type="text" name="name" placeholder="name">
    <input type="text"  name="age" placeholder="age">
    <input type="submit" name="submit" value="add">
    <input type="submit" name="submit" value="retrieve">
</form>

So it should call the @app.route() thing I have here, no?

@app.route('index', methods=['POST', 'GET'])
def index():
    ...

But it doesn't! I've been googling and trying to consult flask's docs for quite some time but I'm just having a really hard time understanding how this stuff works.

When I submit the form, it returns to the page, which is desired. But, the code in index() is not being executed. This I know with 100% certainty the code in index() is not being executed because the first line is a return statement with a string that reads "Hello, world!" and it does not appear.

How do I execute the code in this method?

Thank you!

Azhraam
  • 77
  • 1
  • 10

1 Answers1

-1

So the issue is in your decorator your route is index which means to run the code you need to point to <your localhost url>/index

@app.route('/index', methods=['POST', 'GET'])
def index():
    return 'hello world'
Mike Tung
  • 4,735
  • 1
  • 17
  • 24
  • I made the suggested changes, but still the code does not execute. I am trying to add information to a database, and nothing is being added to that database. Yet, I'm not seeing any errors anywhere from those lines of code. – Azhraam Apr 24 '17 at 14:38
  • did you go the url? what did it respond with? – Mike Tung Apr 24 '17 at 15:02