lesson 3 Flashcards
1
Q
What is port forwarding?
A
- Port forwarding allows us to open pages in our browser from the web server from our virtual machine as if they were being run locally
2
Q
What is __name__?
A
- Contains the name of the running application
- This includes the main application running in python and all the imports.
- The application is called “__main__”
3
Q
What is a decorator?
A
@app.route('/') def hola():
Calls the hola() function
4
Q
urls with variables
A
- “path/”
- type can be a string, int, path
5
Q
How to render templates?
A
- import render_template
- render_template(template.html,variable)
- {% logical code %}
- {{ print }}
6
Q
Make that flask listens to GET and POST
A
- @app.route(‘restaurants’, methods=[‘GET’,’POST’])
- import request
7
Q
How to redirect to another url?
A
return redirect(url_for())
8
Q
How to add messages that appear after a certain action is done?
A
- import flash
- to create the message»_space; flash(“new item created”)
- get_flashed_messages()
9
Q
How to add css, js or media files to flask?
A
- Put them in a file called static
- To write the route to the file in the use {{url_for(‘static’, filename=’style.css’)}}
10
Q
How to send JSON info through api’s?
A
1) Create a serialize property in the class MenuItem in database-setup.py
2) import jsonify
3) Add a @app.route and create a function that returns the json