Flask is known as light weight and feature rich. It is also known as a micro framework. Django is the heavy weight one. Used to dynamically code and update web applications, including Single Page Applications (SPA). It is a web development framework, not a library. Frameworks has certain philosophy, strategy as well as code patterns (for example must follow certain folder structure because the framework will automatically look for assets into those folders, as well as file, resource naming conventions). Frameworks can help us do routine tasks, which we have to do over and over again in web programming, way faster and more efficiently. It uses tried and true methods, and code patterns to implement common web app components, there is no need to reinvent the wheel every time.
Model-View Controller framework
MVC framework, popularized by Ruby on Rails. MVC is a separation of concerns, a way of organizing and designing code projects.
Controller: use a decorator like and URL like structure to define behaviors. Of how the URL will be handled. Called routes. Url_for() short hand to link url to functions instead having to type long url
Database
SQL
Manage Flask ORM resources and records using
SQLAlchemy
Launching Flask app via local server
$ flask run
Use above to launch a local website
Additional Flask concepts
Hello world, first script is commonly called app.py
$python app.py
$python app.py
Jinja mixes Python and HTML together. Url_for() short hand to link url to functions instead having to type long url
Conditional HTML Jinja templating language along with Flask allows us to write if else statement in HTML
How to host flask applications: one example is that you can easily deploy flask applications on Heroku as well as separately on Google Cloud app engine.
Conditional HTML Jinja templating language along with Flask allows us to write if else statement in HTML
How to host flask applications: one example is that you can easily deploy flask applications on Heroku as well as separately on Google Cloud app engine.
Some useful Heroku commands:
$heroku open
opens deployed app.
Fun fact, Salesforce owns Heroku now.
__name__ the use of name keyword can determine whether a script is the main process that is being run, or it is being called upon by another script. If it is imported, then it is called by another script. Check whether the python __name__ == __main__ can inform Flask where to automatically look for static files.
Flask has debugging mode, which should never be used in production but is handy when developing.
Make Flask app available online use ngrok
No comments:
Post a Comment