summaryrefslogtreecommitdiffstats
path: root/README.md
blob: 19baa71de816b130b3bd308f03c8c5da553682c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# flask-tutorial

https://flask.palletsprojects.com/en/3.0.x/tutorial

https://flask.palletsprojects.com/en/3.0.x/tutorial/next/

## Installation

```bash
python -m venv .venv
source .venv/bin/activate

pip install -r requirements.txt
flask --app ustayml run --debug
```

## Build

```bash
pip install build
python -m build --wheel
```

Deploy: https://flask.palletsprojects.com/en/3.0.x/deploying/


## Learning resources

* [Flask user guide](https://flask.palletsprojects.com/en/3.0.x/#user-s-guide)
* DB: https://sqlite.org/lang.html
* [Jinja Template](https://jinja.palletsprojects.com/templates/)
  * [For loops](https://jinja.palletsprojects.com/en/3.1.x/templates/#for)
* [Python packaging tutorial](https://packaging.python.org/en/latest/tutorials/packaging-projects/)

Concepts:

* flask.g: Store data.  Unique for each request
* flask.current_app:  Link to Flask app
* flask.open_resource:  From app package path
* request: HTML request???
* Factory function > registered functions and blueprints.
* Blueprint: groups views & other code
* View: function that returns HTML
* flask.session: dict that stores data across requests (cookies) (securely
  signed with SECRET_KEY)
* *endpoint*: name associated with a view, `<blueprint_name>.<view_function_name>`
* Templates: Used to render HTML.  Uses Jinja template library.  Autoscapes any
  data that is rendered in HTML templates, so it's safe to render user input.
  * `{{ }}` denotes expressions (output) (similar to python)
  * `{% %}` denotes control flow statements (similar to pseudo-code)
  * `{# #}` denotes a comment
  * Automatically available: `g`, `url_for`, `request`, and more
  * In base.html you define "blocks" placeholder which are later defined in
    other templates that extend base.html

Gotchas:

* Remember to call db.commit() after modifying DB (DML).

Browser warnings and errors:

* https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value

## Discussion

Pros:

* Flask is AWESOME, it's simple, it's elegant, it's enjoyable to code with.
  Following the tutorial provides you all the basic tools to begin creating
  projects with flask.  
* It's secure, provides you with cryptographic signature for cookies and escapes
  HTML transparently to the developer.

Cons:

* Maybe scalability and performance is lower compared to PHP or Javascript
  web applications.

## Next Steps

* https://www.sqlalchemy.org/
* https://stackoverflow.com/questions/10434599/get-the-data-received-in-a-flask-request