- #Pretty printed flask cheat sheet how to#
- #Pretty printed flask cheat sheet install#
- #Pretty printed flask cheat sheet series#
You can have as many functions as you want scattered across the application, but in order for that functionality to be accessible from anything external to the application, you must decorate that function and specify a route to make it into a view. (We'll look at this later.)Īny view you specify must be decorated by app.route to be a functional part of the application. The app.route decorator decorates the first view function it can specify one of the routes used to access the application.
#Pretty printed flask cheat sheet how to#
This lets Python know how to import from files relative to this one. app is an instance of Flask, taking in the _name_ of the script file. This is the most basic complete Flask application.
"""Print 'Hello, world!' as the response body.""" If you're using pipenv (like I am), you can locate your virtual environment with pipenv -venv and set up that environment variable in your environment's activate script. This is where all the Flask application goodness will go, and you'll create an environment variable that points to that file. The app.py file will be the application's root. The _init_.py file allows you to import from todo as if it were an installed package. Within the todo directory containing your source code, create an app.py file and a blank _init_.py file. For more information on how to write an installable Python distribution, check out the docs on setup.py.
#Pretty printed flask cheat sheet install#
You'll also have everything you need to set up and install the package in site-packages. This way, whenever you want to install or deploy your project, you'll have all the necessary packages in the requires list. To get there, enter the following on the command line:įrom setuptools import setup, find_packagesĭescription = 'A To-Do List built with Flask' , I like to do this type of work within a Python 3 virtual environment. You'll also want to install flask-sqlalchemy so your Flask application has a simple way to talk to a SQL database. First create a directory to work in (something like flask_todo is a fine directory name) then install the flask package. Like most widely used Python libraries, the Flask package is installable from the Python Package Index (PPI). I'll describe those aspects of each framework in this series, which will begin with Flask.
#Pretty printed flask cheat sheet series#
This series is designed to help developers answer that question by comparing those four frameworks.