Flask

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Explain the process of the request-response cycle

1.) User issues a request to routes.py 2.) Routes.py finds the correct HTML file and python functions in the templates folder 3.) The HTML fetches the CSS, JS, and images it needs from the static folder 4.) Rendered HTML is returned to the user

What file do the apps CSS, javascript, and images go in?

Static

What file does the HTML go in?

Templates

What file does routes.py go in?

The main project folder

Create a new usable instance of flask and save as "app"

app = flask(__name__)

Write the code that will tell flask to render the template index.html when the user visits the url "/"

app.route("/") def index(): render_template("index.html")

HTML content on a page that inherits HTML from another must go in between:

{% block content %} {% end block %}

What do you put in your HTML of a base template where you want a child template to be able to add/change something

{% block content%} {% end block %}

What do you use under the href attribute for the css file? why?

{{ url_for("static", filename="css/main.css") }} this tells flask to generate the url that points to the css file named

What should the last couple of lines in your routes.py file be?

if __name__ == "__main__": app.run(debug=True)

What should the HTML template that each page shares be called?

layout.html

What file interacts with the database?

models.py

How does a button talk to the flask file

the href can pass variables to flask using the url

What should your import show?

from flask import Flask, render_template

The home page of your app should be named

index.html

If using templates makes web pages the same, how can you make them differentiate slightly?

Child pages inherit the HTML from a base template but can then be edited further independently

Show the code needed to input a variable "foo" into an HTML template, in both the python and HTML files

HTML: {{ foo }} Python: (inside of app.route) templateData = { 'variable' : 'value'} return render_template('main.html', **templateData)

What does this do? app.route("/")

It is the opening line of the function that will tell flask what to do when the user visits the url "/"

What does this do? {% extends "layout.html" %}

Tells flask that this template inherits from layout.html

What are web templates for?

They allow you to edit the HTML on multiple pages all at once


Ensembles d'études connexes

Prefix "de" meaning down, off of

View Set

MODULE 4: THE NETIQUETTE AND THE COMPUTER ETHICS (Module Version)

View Set

Effects of HIV infection on the immune system

View Set