> For the complete documentation index, see [llms.txt](https://ga0-2.gitbook.io/seifxr10anz-content/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ga0-2.gitbook.io/seifxr10anz-content/week-8/day-1-html-forms-using-a-web-server/html-forms-in-flask.md).

# HTML forms in flask

Take a quick look at [HTML forms recap](/seifxr10anz-content/week-5/day-2-dom-recap-and-introduction-to-form-elements/forms-in-html.md) to refresh your memory on HTML forms

### Render a form in HTML response

```python
from flask import Flask, request
app = Flask(__name__)

@app.route('/')
def index():
    # Or just put this HTML in a template
    return """
<form method="GET" action="/greeting">
    <input type="text" name="username">
    <input type="submit">
</form>
"""
```

Feel free to play around with the above snippet by building a form using other inputs like:

* Select
* Radio buttons
* Text area
* etc.

### Handling form response

Notice the `action` and `action` attributes on the form element. We will now build a route that can handle the data submitted on the form.

```python
@app.route('/greeting')
def greeting():
    username = request.args.get('username')
    return f"<h1>Hi {username}</h1>"
```
