Flask Guide - Part 1. Install and Set up

Categories:   web development  
Tags:   python   flask  

This is part 1 of the “Flask Guide”.

You can check the next post here.

Create a website using Flask

This is my personal notes on the Flask Python framework.

Feel free to take a look, but the post won’t be explained thoroughly.

Writing posts like these help me learn quicker.

(I’m using virtualenv but you can use pipenv.)

Credits

These are the sources I used:

Flask Install and Set up

This section will cover:

  • Python Virtual Env Setup
  • The Flask install
  • Basic Routes

Prerequisites

  • Install Python on your local machine.
  • Set up a virtual environment (optional)
  • Install git, gitbash
  • A text editor such as atom or VSC

Set up the project folder

  • create project folder and a virtual env:
mkdir flask
cd flask
pip install virtualenv
virtualenv --version
virtualenv .venv
source .venv/Scripts/activate
pip install flask
pip freeze > requirements.txt
touch begin.py
  • Paste the following to begin.py:
from flask import Flask
app = Flask(__name__)

@app.route("/")
@app.route("/home")
def home():
    return "hello world"

@app.route("/about")
def about():
    return "the about page"

if __name__ == '__main__':
    app.run(debug=True)
  • Run the server:
py begin.py
  • Check the site in browser at: localhost:5000
  • and at: localhost:5000/about

I think we will end this section here.

We’ll cover more in the next post.

Related Products



Categories:   web development  
Tags:   python   flask