Flask Flashcards

1
Q

What is Flask?

A

It is a server technology. It is a web framework. Django is a framework.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a virtual environment?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

When I install Flask why are there other applications that need to be included?

A

Needs them, dependencies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a framework?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a microframework?

A

Like a framework but for a minimalistic web application. Less complex than a full stack framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

localhost: 5000

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are routes?

A

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”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a static file?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Review: What is a primitive data type?

A

Integers, strings, and floats

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Review: What is a data structure?

A

List, dictionary, tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Review: What is OOP?

A

Create objects based on classes and assign attributes and methods to them .

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Flask, also what type of framework is it?

A

Simplicity to build a server, it’s simplicity is why it’s good to learn first as a framework

Flask is a micro framework

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a template

A

Something generated in Flask that you can send back as a simple HTML document

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are the key topics you should be familiar with regardless of technology?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are some concepts we should always focus on when learning flask?

A

Rendering templates, redirecting, form data, get & post requests, session

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If we want to use flask or any pip module, what do we want to use?

A

A virtualenv

17
Q

What is a python virtual environment?

A

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.

18
Q

List the steps to creating a virtual environment using flasdk

A

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:

19
Q

How do I deactivate my flask environement

A

Just type the deactivate in the command line. Closing your terminal window will also deactivate your virtual environment. pip list shows dependencies

20
Q

Review: What is pip?

A
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
21
Q

Routes are essential part of any web application. A route is much like

A

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.

22
Q

What is special about templates?

A

We need to call to a directory called templates

23
Q

What are the two most common HTTP request methods that fit into web apps

A

Two most common are GET and POST

24
Q

What is the GET method?

A

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

25
Q

What is you were signing into your email and we used a GET method. How horrible would it be if you submitted the login form and your SN and PW were displayed in your URL?

A

POST to the Rescue! Passes data behind the scenes in the HTTP request message body. These requests are never cached, not saved in your history, can’t be bookmarkeed and aren’t limited to how much data that can be sent. The vast majority of form you’rll be dealing with will use POST requests to send data. In, general forms should ALWAYS be sent using the POST method unless you will need to give users the ability to preserve a query string, as in a Google search.

26
Q

What about PUT PATCH and DELETE

A

These exits for the express purpose of designing APIs. These are not supported methods in your HTML code, and only work when being handled by JS AJAX requests

27
Q

Review: What are forms?

A

The modern internet is user-driven; much of the actual content of a website is generated by the users of a website. How does the user manage to get his or her data to the page?? One word: forms. The HTML forms are the way in which users are able to pass data to the back end of a website where it can be processed and stored. Processing form data correctly is a huge part of what it takes to become a back-end developer.

28
Q

Why is the input element so important in forms?

A

The form tag will set up all of the logistics, but the information you want to gather will be harvested from the elements you place within the form. In our basic example, we have just one type of input, a text field. There are several different input types that can gather data:
Decide on the input elements you want to include in your form. Each must be assigned a name attribute if you want each input to be recognized by your server-side code. When the HTML form gathers up your data it will create a set of key/value pairs with the name attributes as the keys and the data the user enters as the values. Notice in our form above that we give a name to each input element that reflects the information we want to gather.

And that’s the front end! The form data will be sent to the server when the user clicks the submit button. The form data is organized into key/value pairs and submitted to the URL specified by your form’s ‘action’ attribute using the HTTP method specified in your form’s ‘method’ attribute.

29
Q

Redirecting?

A

In our POST route we used the redirect method to send a new request to the ‘/’ route. We can redirect to any route that we have defined:

30
Q

Flask templates (using Jinja2)…how would you do a for loop?

A

{% for x in range (0,5) %}

<p> {{ x }} </p>

{% endfor %}

31
Q

Do the bulk of your logic where?

A

In your python code and not embedded in your html since it will slow down your server response time

32
Q

What is session?

A

Remember, an HTTP request/response cycle, it is stateless. That means that each request/response cycle instance is independent and ignorant of any instances that came before or will come after it….

but how does your retailr know and rememer, who you are (account), what you’ve searched for, the items in i your cart, etc….THROUGH PERSISTENT DATA STORAGE. You can use a databaser or you can also come in the form of writing to a file, and that is what session doess

Its like the user can have a conversation of sorts with the web site where a user makes decision that can e tracked so that the server can respond appropriately to create a better user experience.

33
Q

Cookies vs databases?

A

You’ve probably heard of the term cookies before. Frameworks like Flask use cookies to store data like sessions. Flask uses secure hashing of session data to send a packet of information from server to client. This packet is known as a cookie. Once your browser has received this cookie, it writes the information contained in it to a small file on your hard drive.

34
Q

What are the steps we need to perform for form validation?

A

1) logic - what data do we want to validate?
2) checking if the data is present
3) making sure the data is in the correct format
4) sending the user to the correct destination whether their data is valid or not
5) alerting the user of their errors (if they exist)

35
Q

What are the most important validation tools for the if/else statement?

A

IF/Else with a return of true or false

36
Q

What are flash messages on the server?

A

Flask messages are string that exist for one redirect cycle. Similar to Session, you can access flask messages through embedded python tags {{}} & {%%} on the views and display them to the user.

37
Q

What is the difference between flash and session?

A

Flash messages only last for one redirect while session stays until it is manually popped. This makes flash messages perfect for validation where we only need to display the error or message temporarily.

38
Q

How can we import databases and use session variables to log a user in?

A

Connecting to MySQL, import and exporting a MySQL database, include file, database communication management, login and registration, mySQL injection

39
Q

What is the terminal command to install mySQL

A

pip install mySQL-python==1.2.5