Lab 11 Notes and Probably Review of Some of the Previous Labs
To make a form with Python:
from flask import Flask, render_template, and request
- Flask is an object that allows for serving websites
- render_template is a method that allows for the serving of html files that are stored in a folder called templates
- request is an object that holds a dictionary that stores the user's inputs of a website. This is linked to the HTML, and will be explained more later on.
var = Flask(__name__) #to create the flask obj
@var.route("/") # to create a site at the root directory. A method that immediately follows this call will create a page with it's return
Alternatively: @var.route("/", methods=['GET']) or @var.route("/", methods=['POST'])
--Note that I have not been able to get methods=['POST'] to work. Must look at Piazza for more info
Afterwards: you can also do
@var.route("/<name>") to create other pages at different URLs, with the /<name> added to the base URL.
USING TEMPLATE
- Have an HTML file in it
- return render_template('fileName') in a method with an @var.route()
The file must be accessed through adding /static/file_name to the URL
If it is not an html file, it will cause a download to occur **REQUESTS and FORMS**
In html, a form can be created like so: ``` whatever else html you want ``` The last input will create a button to be used to complete the form and bring you to the next page.