How to Build and Start the Project

This document provides a step-by-step guide on building and starting the benhall/flask-demo project.

Prerequisites

Before you start, ensure you have the following:

  • Python 3: The project is written in Python 3.
  • pip: The Python package installer.

Building the Project

  1. Clone the repository:

    git clone https://github.com/benhall/flask-demo.git
    
  2. Navigate to the project directory:

    cd flask-demo
    
  3. Install the dependencies:

    pip install -r requirements.txt
    

Running the Project

  1. Start the Flask development server:

    flask run
    
  2. Access the application: The application will be accessible at http://127.0.0.1:5000/.

Testing the Project

  1. Run the tests:
    make test
    

Code Examples

Creating Blueprints:

Registering Blueprints in the Application:

  • app.py

    from flask import Flask
    from .blueprints.greetings import greetings
    
    app = Flask(__name__)
    app.register_blueprint(greetings)
    

Defining Routes and Handlers:

  • blueprints/greetings.py

    @greetings.route('/hello')
    def hello():
        """
        Returns a greeting message.
    
        Returns:
            str: A greeting message.
        """
        return 'Hello there!'
    

Defining the Main Application Route:

  • app.py

    @app.route('/')
    def index():
        """
        This function returns a welcome message for the Flask demo with Blueprints.
        """
        return 'Welcome to the Flask demo with Blueprints!'
    

Additional Information

  • Makefile: The Makefile provides convenient commands for building, testing, and running the project.

    make install # Install dependencies
    make run # Run the application
    make test # Run tests
    make coverage # Generate coverage report
    
  • Requirements: The requirements.txt file lists the project’s dependencies.