Skip to content

Project Layout

This follows the basic structure that most Flask projects follow. It can work with different layouts (eg. one file) but this is not recommended. Follow Python Setup guide to get your project ready with everything installed. You will also need to install flask follow the dependency instructions.

Project Structure

A basic flask project could be a simple file with everything in one place:

main.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'

Using a single file doesn’t scale to larger websites and becomes confusing and difficult to navigate. For this reason projects are split into multiple files to organise the code by function. We will have a main app folder called flaskapp which will contain our app, database and our html pages, we will also have a folder to house our automated tests.

  • Directoryflaskapp/
    • Directorystatic/
      • style.css
    • Directorytemplates/
      • Directoryblog/
        • create.html
        • index.html
        • post.html
        • search.html
      • Directorycomponents/
        • comment.html
        • footer.html
        • navbar.hyml
        • post.html
      • base.html
    • __init__.py
    • blog.py
    • db.py
    • schema.sql
  • Directorytests/
    • __init__.py
    • conftest.py
    • data.sql
    • test_blog.py
    • test_factory.py
    • test_db.py