Setting Up the HTML Structure and Project Layout with FastAPI
Introduction and Overview
Welcome to the first lesson of our course on building a Short Story Generation Web Application with FastAPI. In this lesson, we will focus on setting up the basic HTML structure for our application. This foundational step is crucial, as it lays the groundwork for the entire web application. By the end of this lesson, you will have a well-structured HTML document that serves as the backbone for our AI Short Story Generator. Let's dive in and start building!
App File Structure
Before we start building the HTML for our story generation interface, let's take a moment to understand how our FastAPI application is organized. A clear file structure helps us stay organized as our project grows in complexity.
Here's the structure we'll be working with:
How FastAPI Serves Static Files and Templates
- Templates:
FastAPIuses theJinja2Templatesclass to renderHTMLtemplates. Templates are stored in thetemplates/directory. - Static Files: Static files such as
CSSandJavaScriptare served usingFastAPI'sStaticFilesclass. These files are placed in thestatic/directory and mounted in theFastAPIapp.
In your FastAPI app, you might mount the static directory like this:
And in your HTML template, you can link to your stylesheet as follows:
This tells FastAPI to serve the style.css file from the static folder.
