This project is a web application built with FastAPI, designed to serve dynamic HTML pages and static assets like CSS, JavaScript, and images.
- Dynamic HTML Rendering using Jinja2 templates.
- Static File Serving for CSS, JavaScript, and images.
- Structured project layout for scalability and maintainability.
my_fastapi_project/
├── app/
│ ├── __init__.py
│ ├── main.py # Entry point for the application
│ ├── core/ # Core configuration, settings, and utilities
│ ├── models/ # Database models and schemas
│ ├── api/ # API routes
│ ├── services/ # Business logic and reusable services
│ ├── db/ # Database-related utilities
│ ├── templates/ # HTML templates for Jinja2 rendering
│ │ ├── index.html
│ ├── static/ # Static files (CSS, JS, images)
│ ├── css/
│ │ ├── styles.css
│ ├── js/
│ │ ├── scripts.js
│ ├── images/
│ ├── logo.png
├── requirements.txt # Python dependencies
Ensure you have the following installed on your system:
- Python 3.8+
- pip (Python package manager)
- Uvicorn (ASGI server)
-
Clone the Repository
Clone this repository to your local machine:git clone https://github.com/your-repo/fastapi-project.git cd fastapi-project -
Create a Virtual Environment
Create and activate a virtual environment to manage dependencies:python -m venv env source env/bin/activate # For Linux/MacOS env\Scripts\activate # For Windows
-
Install Dependencies
Install the required Python packages:pip install -r requirements.txt
-
Project Configuration
Ensure the directory structure is intact:- Place HTML files in the
app/templates/folder. - Place CSS, JS, and images in the
app/static/folder.
- Place HTML files in the
-
Start the Server
Run the FastAPI server using Uvicorn:uvicorn app.main:app --reload
-
Access the Application
Open your web browser and navigate to:http://127.0.0.1:8000