Visual Studio Code with Python Flask

I wanted to continue on my python exploration and show how to get started with Visual Studio Code with Python Flask.
What is flask you may ask

Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions. And before you ask: It’s BSD licensed!

Basically you can think of Flask somewhat like NancyFx or Sinatra web framework.

First thing first, in python we should set up our virtualenv such that we have a dev environment and don’t pollute our global space with our packages. You should already have pip install with your python if you are using the Python 3.x series.

Open up your powershell or command prompt and type

Once you have virtualenv we will need virtualenvwrapper-win since we are running under windows.

Now we need to create the virtualenv that we will be using.

This will create your virtualenv inside your home directory for mine it is under

In order to activate the virtualenv we need to use the activate.ps1 script but you must make sure we have the correct execution-policy in your powershell but before we do that lets launch our Vscode

Lets now set up our directory to use the virtualenv, remember the Set-ExecutionPolicy for powershell and use the terminal inside your vscode with Ctrl+Shift+` (right tick)

Lets now install flask

Lets now create a hello.py example of flask application, remember spaces are important for python

Go back to your powershell prompt and enter. (NOTE: you may need to restart vscode for this to work)

When everything is up and running you should be able to go to Chrome or your favourite browser and view port 5000 and see Hello world there.

VsCode-Python-Flask-1

VsCode-Python-Flask-1

Hope this helps you in setting up vscode with development of Python Flask.

To learn about running VSCode with python read my previous post on Getting Started with Visual Studio Code with Python.