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
Clone the repository:
git clone https://github.com/benhall/flask-demo.git
Navigate to the project directory:
cd flask-demo
Install the dependencies:
pip install -r requirements.txt
Running the Project
Start the Flask development server:
flask run
Access the application: The application will be accessible at
http://127.0.0.1:5000/
.
Testing the Project
- Run the tests:
make test
Code Examples
Creating Blueprints:
-
from flask import Blueprint greetings = Blueprint('greetings', __name__)
-
from flask import Blueprint data = Blueprint('data', __name__)
Registering Blueprints in the Application:
-
from flask import Flask from .blueprints.greetings import greetings app = Flask(__name__) app.register_blueprint(greetings)
Defining Routes and Handlers:
-
@greetings.route('/hello') def hello(): """ Returns a greeting message. Returns: str: A greeting message. """ return 'Hello there!'
Defining the Main Application Route:
-
@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.