From 5a732002185b50adca25de70b2d8d35bed0e056b Mon Sep 17 00:00:00 2001 From: tejcapildeo <96087837+tejcapildeo@users.noreply.github.com> Date: Wed, 22 Nov 2023 18:01:49 -0500 Subject: [PATCH 1/5] Creating Flask.md This is the introduction to Flask, specifically including the usage of Flask-SQLAlchemy as the database solution. This is the first draft, as it will be reviewed by other group members and changes will be made to improve it. --- Topics/Tech_Stacks/Flask.md | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Topics/Tech_Stacks/Flask.md diff --git a/Topics/Tech_Stacks/Flask.md b/Topics/Tech_Stacks/Flask.md new file mode 100644 index 000000000..f5eae1ad3 --- /dev/null +++ b/Topics/Tech_Stacks/Flask.md @@ -0,0 +1,63 @@ +# Intro to Flask with Flask-SQLAlchemy + + +## Introduction +### What is Flask and why is it useful? +Flask is a lightweight and flexible web framework for Python. Developed by Armin Ronacher, it is designed to be simple and easy to use, providing the essentials for building web applications without imposing rigid structures. Flask is often referred to as a "micro" framework because it focuses on keeping the core simple and extensible, allowing developers to choose the tools and libraries they need. + +The inclusion of the Jinja2 templating engine, built-in development server and Flask's native support for RESTful request handling are desirable features. Its versatility in deployment and suitability for prototyping and small to medium-sized projects make Flask an ideal framework for projects where customization and control over the stack are key considerations. + +Here is an overview of Flask: +https://flask.palletsprojects.com/en/3.0.x/# + +### What is Flask-SQLAlchemy and why is it useful? + +Flask-SQLAlchemy is an extension for Flask that integrates SQLAlchemy, a powerful SQL toolkit and Object-Relational Mapping (ORM) library, into Flask applications. This extension simplifies database interactions by providing a convenient interface for defining models, executing queries, and managing database connections seamlessly within the Flask framework. + +Some of the advantageous features include seamless integration with Flask, session handling, support for Flask Script and Flask Restful, compatibility with Flask extensions and database migrations. + + + +## Getting set up +### Setting up Flask: +First install Flask following the instructions here +https://flask.palletsprojects.com/en/3.0.x/installation/ + +This will make sure that all dependencies are obtained, the virtual environment is created and Flask is installed. + +Next, the Flask application can be set up. +This shows you how the project layout works: +https://flask.palletsprojects.com/en/3.0.x/tutorial/layout/ + +And this is how to set the application up: +https://flask.palletsprojects.com/en/3.0.x/tutorial/factory/ + +Alternatively, there is also this useful quickstart guide for getting started quickly: +https://flask.palletsprojects.com/en/3.0.x/quickstart/ + +### Setting up Flask-SQLAlchemy: +Note that Flask-SQLAlchemy is a wrapper around SQLAlchemy, so it will be useful to check out the documentation and tutorial for using SQLAlchemy linked here: +https://docs.sqlalchemy.org/en/20/tutorial/index.html + +Then follow these steps to get Flask-SQLAlchemy installed, then initialize and configure extensions. It also shows how to define models and create tables : +https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/quickstart/#installation + + +## Basic useful features +### Flask +Here is the documentation with the basics needed to start developing using Flask. It assumes knowledge of Python, which I think should be safe to assume. +https://flask.palletsprojects.com/en/3.0.x/tutorial/ + + +### Flask-SQLAlchemy: +Here are the basic useful features for using queries with Flask-SQLAlchemy. It shows the basics of things like inserting, deleting and updating in the database, selecting, and finally querying for views. +https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/queries/ + + +## Conclusion +In the dynamic landscape of web development, the tandem use of Flask and Flask-SQLAlchemy emerges as a compelling solution, seamlessly blending simplicity with robust database capabilities. Setting up a Flask application becomes a swift endeavor, marked by the ease of installation and quick configuration. Flask's minimalistic design empowers developers with the freedom to choose and integrate components, facilitating rapid prototyping and efficient development. With the added integration of Flask-SQLAlchemy, the database layer becomes an integral part of the Flask ecosystem, offering a unified and expressive interface for model definition, database querying, and session management. Ultimately, the Flask and Flask-SQLAlchemy duo empowers developers to create scalable, maintainable, and feature-rich web applications. + + +## Additional Resources +Here is the overview for the Flask documentation: +https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/ From b0dc26e76669df21ee1e5d0844dc270f16de12d5 Mon Sep 17 00:00:00 2001 From: tejcapildeo <96087837+tejcapildeo@users.noreply.github.com> Date: Thu, 23 Nov 2023 23:41:14 -0500 Subject: [PATCH 2/5] Update Flask.md by adding to additional resources Added more to additional resources including a link to an overview of the Flask-SQLAlchemy documentation, as well as a useful video for getting started with Flask-SQLAlchemy. --- Topics/Tech_Stacks/Flask.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Topics/Tech_Stacks/Flask.md b/Topics/Tech_Stacks/Flask.md index f5eae1ad3..783ba1efa 100644 --- a/Topics/Tech_Stacks/Flask.md +++ b/Topics/Tech_Stacks/Flask.md @@ -60,4 +60,10 @@ In the dynamic landscape of web development, the tandem use of Flask and Flask-S ## Additional Resources Here is the overview for the Flask documentation: +[https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/](https://flask.palletsprojects.com/en/3.0.x/) + +Here is an overview for the Flask-SQLAlchemy documentation: https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/ + +And here is a useful video for learning about Flask-SQLAlchemy: +https://www.youtube.com/watch?v=uZnp21fu8TQ&t=1s&ab_channel=TechWithTim From 44227b7cca0d0f1c6d3242d277c8ceb1a5f4327f Mon Sep 17 00:00:00 2001 From: tejcapildeo <96087837+tejcapildeo@users.noreply.github.com> Date: Fri, 24 Nov 2023 18:49:44 -0500 Subject: [PATCH 3/5] Reformatted Flask.md Reformatted the document by making links clickable words to make it cleaner, as well as numbering each section to improve the flow. This should make it easier to read and follow. --- Topics/Tech_Stacks/Flask.md | 49 +++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/Topics/Tech_Stacks/Flask.md b/Topics/Tech_Stacks/Flask.md index 783ba1efa..e3993cd6c 100644 --- a/Topics/Tech_Stacks/Flask.md +++ b/Topics/Tech_Stacks/Flask.md @@ -1,14 +1,13 @@ # Intro to Flask with Flask-SQLAlchemy -## Introduction -### What is Flask and why is it useful? +## 1. Introduction +### What is Flask and why is it useful? Flask is a lightweight and flexible web framework for Python. Developed by Armin Ronacher, it is designed to be simple and easy to use, providing the essentials for building web applications without imposing rigid structures. Flask is often referred to as a "micro" framework because it focuses on keeping the core simple and extensible, allowing developers to choose the tools and libraries they need. The inclusion of the Jinja2 templating engine, built-in development server and Flask's native support for RESTful request handling are desirable features. Its versatility in deployment and suitability for prototyping and small to medium-sized projects make Flask an ideal framework for projects where customization and control over the stack are key considerations. -Here is an overview of Flask: -https://flask.palletsprojects.com/en/3.0.x/# +Here is an overview of Flask: [Flask Overview](https://flask.palletsprojects.com/en/3.0.x/#) ### What is Flask-SQLAlchemy and why is it useful? @@ -18,52 +17,48 @@ Some of the advantageous features include seamless integration with Flask, sessi -## Getting set up +## 2. Getting set up ### Setting up Flask: -First install Flask following the instructions here -https://flask.palletsprojects.com/en/3.0.x/installation/ +First install Flask following the instructions here: [Flask installation](https://flask.palletsprojects.com/en/3.0.x/installation/) This will make sure that all dependencies are obtained, the virtual environment is created and Flask is installed. Next, the Flask application can be set up. -This shows you how the project layout works: -https://flask.palletsprojects.com/en/3.0.x/tutorial/layout/ +This shows you how the project layout works: [Project Layout](https://flask.palletsprojects.com/en/3.0.x/tutorial/layout/) -And this is how to set the application up: -https://flask.palletsprojects.com/en/3.0.x/tutorial/factory/ +And this is how to set the application up:[Application Setup](https://flask.palletsprojects.com/en/3.0.x/tutorial/factory/) -Alternatively, there is also this useful quickstart guide for getting started quickly: -https://flask.palletsprojects.com/en/3.0.x/quickstart/ +Alternatively, there is also this useful quickstart guide for getting started quickly:[Quickstart Guide](https://flask.palletsprojects.com/en/3.0.x/quickstart/) ### Setting up Flask-SQLAlchemy: Note that Flask-SQLAlchemy is a wrapper around SQLAlchemy, so it will be useful to check out the documentation and tutorial for using SQLAlchemy linked here: -https://docs.sqlalchemy.org/en/20/tutorial/index.html +[SQLAlchemy Documentation](https://docs.sqlalchemy.org/en/20/tutorial/index.html) -Then follow these steps to get Flask-SQLAlchemy installed, then initialize and configure extensions. It also shows how to define models and create tables : -https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/quickstart/#installation +Then follow [these steps](https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/quickstart/#installation) to get Flask-SQLAlchemy installed, then initialize and configure extensions. It also shows how to define models and create tables. -## Basic useful features + +## 3. Basic useful features ### Flask Here is the documentation with the basics needed to start developing using Flask. It assumes knowledge of Python, which I think should be safe to assume. -https://flask.palletsprojects.com/en/3.0.x/tutorial/ +[Flask Basics](https://flask.palletsprojects.com/en/3.0.x/tutorial/) ### Flask-SQLAlchemy: Here are the basic useful features for using queries with Flask-SQLAlchemy. It shows the basics of things like inserting, deleting and updating in the database, selecting, and finally querying for views. -https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/queries/ +[Flask-SQLAlchemy Basics](https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/queries/) -## Conclusion +## 4. Conclusion In the dynamic landscape of web development, the tandem use of Flask and Flask-SQLAlchemy emerges as a compelling solution, seamlessly blending simplicity with robust database capabilities. Setting up a Flask application becomes a swift endeavor, marked by the ease of installation and quick configuration. Flask's minimalistic design empowers developers with the freedom to choose and integrate components, facilitating rapid prototyping and efficient development. With the added integration of Flask-SQLAlchemy, the database layer becomes an integral part of the Flask ecosystem, offering a unified and expressive interface for model definition, database querying, and session management. Ultimately, the Flask and Flask-SQLAlchemy duo empowers developers to create scalable, maintainable, and feature-rich web applications. -## Additional Resources -Here is the overview for the Flask documentation: -[https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/](https://flask.palletsprojects.com/en/3.0.x/) +## 5. Additional Resources +[Here](https://flask.palletsprojects.com/en/3.0.x/) is the overview for the Flask documentation. + + +[Here](https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/) is an overview for the Flask-SQLAlchemy documentation. + -Here is an overview for the Flask-SQLAlchemy documentation: -https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/ +And [here](https://www.youtube.com/watch?v=uZnp21fu8TQ&t=1s&ab_channel=TechWithTim) is a useful video for learning about Flask-SQLAlchemy: -And here is a useful video for learning about Flask-SQLAlchemy: -https://www.youtube.com/watch?v=uZnp21fu8TQ&t=1s&ab_channel=TechWithTim From 4d1369f685fbf63702be973b891532589801de7c Mon Sep 17 00:00:00 2001 From: tejcapildeo <96087837+tejcapildeo@users.noreply.github.com> Date: Fri, 24 Nov 2023 19:05:24 -0500 Subject: [PATCH 4/5] Update Flask.md by adding some documentation on troubleshooting In the additional resources section, I included documentation about troubleshooting some common problems that users run into while using Flask. --- Topics/Tech_Stacks/Flask.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Topics/Tech_Stacks/Flask.md b/Topics/Tech_Stacks/Flask.md index e3993cd6c..fd21424cc 100644 --- a/Topics/Tech_Stacks/Flask.md +++ b/Topics/Tech_Stacks/Flask.md @@ -60,5 +60,9 @@ In the dynamic landscape of web development, the tandem use of Flask and Flask-S [Here](https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/) is an overview for the Flask-SQLAlchemy documentation. -And [here](https://www.youtube.com/watch?v=uZnp21fu8TQ&t=1s&ab_channel=TechWithTim) is a useful video for learning about Flask-SQLAlchemy: +[Here](https://www.youtube.com/watch?v=uZnp21fu8TQ&t=1s&ab_channel=TechWithTim) is a useful video for learning about Flask-SQLAlchemy: + +[Here](https://flask.palletsprojects.com/en/2.3.x/errorhandling/) is a link to some common errors that users run into with Flask. + + From a4d5be60f3a70ea90ea8a242929edf9e2f8b883d Mon Sep 17 00:00:00 2001 From: tejcapildeo <96087837+tejcapildeo@users.noreply.github.com> Date: Fri, 24 Nov 2023 22:01:40 -0500 Subject: [PATCH 5/5] Update Flask.md with a summary of installation steps Included summary of installation steps within the document for quick and easy reference for the user. --- Topics/Tech_Stacks/Flask.md | 59 ++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/Topics/Tech_Stacks/Flask.md b/Topics/Tech_Stacks/Flask.md index fd21424cc..0005bf487 100644 --- a/Topics/Tech_Stacks/Flask.md +++ b/Topics/Tech_Stacks/Flask.md @@ -22,6 +22,21 @@ Some of the advantageous features include seamless integration with Flask, sessi First install Flask following the instructions here: [Flask installation](https://flask.palletsprojects.com/en/3.0.x/installation/) This will make sure that all dependencies are obtained, the virtual environment is created and Flask is installed. +Here is a summary of the steps: +Create an environment: +```bash +> mkdir myproject +> cd myproject +> py -3 -m venv .venv +``` +Activate the environment: +```bash +> .venv\Scripts\activate +``` +Install flask: +```python +$ pip install Flask +``` Next, the Flask application can be set up. This shows you how the project layout works: [Project Layout](https://flask.palletsprojects.com/en/3.0.x/tutorial/layout/) @@ -36,7 +51,49 @@ Note that Flask-SQLAlchemy is a wrapper around SQLAlchemy, so it will be useful Then follow [these steps](https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/quickstart/#installation) to get Flask-SQLAlchemy installed, then initialize and configure extensions. It also shows how to define models and create tables. - +Here is a summary of the steps: +Install Flask-SQL with: +```bash +$ pip install -U Flask-SQLAlchemy +``` +Initialize the extensions: +```python +from flask import Flask +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.orm import DeclarativeBase + +class Base(DeclarativeBase): + pass + +db = SQLAlchemy(model_class=Base) +``` + +Configure the extensions: +```python +# create the app +app = Flask(__name__) +# configure the SQLite database, relative to the app instance folder +app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///project.db" +# initialize the app with the extension +db.init_app(app) +``` + +Define models: +```python +from sqlalchemy import Integer, String +from sqlalchemy.orm import Mapped, mapped_column + +class User(db.Model): + id: Mapped[int] = mapped_column(Integer, primary_key=True) + username: Mapped[str] = mapped_column(String, unique=True, nullable=False) + email: Mapped[str] = mapped_column(String) +``` + +Create tables: +```python +with app.app_context(): + db.create_all() +``` ## 3. Basic useful features ### Flask