Flask Flashcards
What is Flask?
It is a server technology. It is a web framework. Django is a framework.
What is a virtual environment?
A folder where you can place all of your information and can hold all projects for that instance. It’s going to store all the software for me
A virtual environment is a clean python environment
When I install Flask why are there other applications that need to be included?
Needs them, dependencies
What is a framework?
It’s a standard structure for how to implement a software project. Contains both the tools needed to do repetitive tasks and then may generate needed project files as well
What is a microframework?
Like a framework but for a minimalistic web application. Less complex than a full stack framework
localhost: 5000
It is a localhost What is :5000…it is a port .
It is like a lane of a highway that all of your traffic is go over. you can change if you want to
What are routes?
Important way to interact with website. It is anything after our .com..THAT”S our route.
Multiple pages at each route. Jinja2 renders our templates for us.
@app.route(“/route”)
What is a static file?
To link to static files we can create a new folder called static. In order to keep the static folder organized we can also create subfolders for css, js and images
Organize your static folder
Review: What is a primitive data type?
Integers, strings, and floats
Review: What is a data structure?
List, dictionary, tuple
Review: What is OOP?
Create objects based on classes and assign attributes and methods to them .
Flask, also what type of framework is it?
Simplicity to build a server, it’s simplicity is why it’s good to learn first as a framework
Flask is a micro framework
What is a template
Something generated in Flask that you can send back as a simple HTML document
What are the key topics you should be familiar with regardless of technology?
Routing,
Clint server cycle - simplified to a degree in Flask. Understanding how it works now will help…which action triggers which events, and what happens when a client makes a request.
Database connection - Every app must connect to a database
What are some concepts we should always focus on when learning flask?
Rendering templates, redirecting, form data, get & post requests, session
If we want to use flask or any pip module, what do we want to use?
A virtualenv
What is a python virtual environment?
Simply put, virtual environments are a tool for creating unique sandboxes to control project dependencies. Each of these virtual environments can contain different versions of Python, Flash, or any combination of packages.
Consider a scenario in which you must put work into 4 projects, each with varying dependencies:
Project 0 – Using Python 2.7.13, Flask 0.10
Project 1 - Using Python 2.7.13, Flask 0.12
Project 2 - Using Python 3.0, Flask 0.10
Project 3 - Using Python 3.4.3, No Flask
This scenario is an excellent use case for the virtualenv Python module. We can create Python environments that are segregated from our system-wide Python installation, with each virtual environment being created specifically for our three projects.
List the steps to creating a virtual environment using flasdk
pip install virtual env (virtual environment for python)
create a folder with a structure to hold your envs
virtualenv flaskEnv (major dependency is flask environment)
source flaskEnv/bin/activate (activate the virtual envrionment)
The (flaskEnv) indicates that your virtualenv is now active. If we install any dependencies they will install into our local flaskEnv folder:
How do I deactivate my flask environement
Just type the deactivate in the command line. Closing your terminal window will also deactivate your virtual environment. pip list shows dependencies
Review: What is pip?
adds packages for python: pip install \_\_\_ pip list = all dependencies pip freeze (requirements file) pip freeze > requirements.txt pip uninstall \_\_\_ pip show Django pip search Flask
Routes are essential part of any web application. A route is much like
A route is much lika . variable name we assign to a request. The job of a route is to communicate to the server what kind of information the client needs. This route name is attached to a rate on our server that points towards a specific
These instructions contain information about how to interpret the data being sent, the operations that need to be completed, and the response that should be sent back.
What is special about templates?
We need to call to a directory called templates
What are the two most common HTTP request methods that fit into web apps
Two most common are GET and POST
What is the GET method?
Any time you visit a website and a page loads in reponse you’re seeing the HTTP GET Method in action! The page is the RESPONSE that have been packaged and returned to your browser in the form of HTML, CSS, and Javascript. So far all of our routes have been for GET requests
{{ x }}
{% endfor %}