Flaskr Project: A Development Log
Building the Flaskr blog application was a comprehensive journey through the fundamentals of web development with Python. This log details the step-by-step process, from the initial setup to full-scale deployment and testing.
Initial Setup and Core Application
The project began with laying the foundational infrastructure. This stage was all about creating the core application factory and database integration.
- Repository Creation: I created a repository on GitHub and cloned it locally to manage version control.
- Virtual Environment: A virtual environment was set up in VS Code to manage project dependencies and keep the project isolated.
- Application Factory: The main application was initialized with the
/flaskr/__init__.py
file, including a simple test route to ensure the dev server was functioning correctly. - Database Integration: I defined the database schema in
schema.sql
and wrote thedb.py
file to handle database connections and run SQL commands. The database was successfully initialized by runningflask --app flaskr init-db
, creating theflaskr.sqlite
file.
User Authentication and Templating
Once the core application was in place, I focused on building out the user authentication system and creating the initial set of templates.
- Authentication Blueprint: A Blueprint named 'auth' was created in
auth.py
to handle user registration, login, and logout views. This Blueprint was then imported and registered in the__init__.py
file. - Base Templates: A foundational
base.html
template was created for consistent site-wide styling. - Authentication Templates: I created specific templates for the
register
andlogin
views attemplates/auth/register.html
andtemplates/auth/login.html
. - Functionality Testing: I ran the dev server to test the authentication flow. All required fields and authentication logic worked as expected, with successful user registration and login.
Blog Blueprint and Content Management
With user authentication complete, the next step was to build the core blog functionality, allowing users to create, edit, and delete posts.
- Blog Blueprint: A 'blog' Blueprint was created in
blog.py
to manage all blog-related views and logic. - Content Views: Routes were added for the blog's index, post creation (
/create
), editing (/update
), and deletion (/delete
). - Blog Templates: Dedicated templates were created for each view at
templates/blog/index.html
,templates/blog/create.html
, andtemplates/blog/update.html
.
Testing, Deployment, and Final Touches
The final stage involved ensuring the application was robust and ready for production.
- Dependency Management: A
pyproject.toml
file was created, and the application was installed in the virtual environment. - Comprehensive Testing: I created a dedicated
tests
folder with test files for the factory, database, and authentication. A data file (data.sql
) was created for testing purposes. Runningpytest
confirmed all tests passed. - Code Coverage: Using
pytest-cov
, I confirmed that the application's source code had 100% test coverage. - Deployment: A wheel file was created for easy deployment, and the application was successfully deployed to a production environment using Render as a hosting provider.
- Final Link: The final Flaskr project is linked Here as a showcase of my work.