mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-04-08 11:56:41 +00:00
34 lines
818 B
Markdown
34 lines
818 B
Markdown
# Flask Requests
|
|
|
|
Specify allowed HTTP methods in `file.py`:
|
|
`@app.route("/page/", methods=["allowed methods"])`
|
|
|
|
## Forms
|
|
|
|
in `file.py`:
|
|
|
|
```py
|
|
from flask import Flask, render_template
|
|
from flask.globals import request
|
|
|
|
@app.route("/login/", methods=["GET", "POST"])
|
|
def login():
|
|
if request.method == "POST": # if POST then form has been filled
|
|
data = request.form["field name"] # store the form's data in variable
|
|
# manipulate form data
|
|
|
|
req_args = request.args # request args
|
|
|
|
else: # if GET then is asking for form page
|
|
return render_template("login.html")
|
|
```
|
|
|
|
In `login.html`:
|
|
|
|
```html
|
|
<html>
|
|
<!-- action="#" goes to page itself but with # at the end of the URL -->
|
|
<form action="#" method="post">
|
|
<input type="text" name="field name">
|
|
</html>
|
|
```
|