Skip to content

treymorgan/Default-Python-Flask-Web-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Default Python Web Application

Author: Trey Morgan

Purpose: This is the default template that I wrote to setup basic functionality for my python websites.

Introduction

This is a simple Python web application built using the Flask framework. It includes basic functionality for user registration, login, and logout, all backed by a SQLite database. The application is styled using CSS and is designed to be easy to deploy and run, either locally or within a Docker container.

Features

  • User Registration: Users can create an account by providing their first name, last name, email, username, and password.
  • User Login/Logout: Registered users can log in and log out securely.
  • Responsive Design: The application is styled with responsive CSS, ensuring it looks good on various devices.

File Overview

1. main.py

This is the main application file. It defines the Flask app and sets up routes for registration, login, logout, and the homepage. The application also handles database interactions and user authentication.

2. base.html

This is the base HTML template that contains the overall structure of the webpage, including the navigation menu, content blocks, and footer. Other HTML files extend this template.

3. login.html

This HTML template extends base.html and provides the layout for the login page. Users can enter their username and password here to log in.

4. register.html

This HTML template extends base.html and provides the layout for the registration page. Users can enter their details here to create a new account.

5. styles.css

This CSS file contains the base styling for the entire application, including body styles, navigation menu styles, and footer styles.

6. login-styles.css

This CSS file contains specific styles for the login and registration pages, such as form layout and input field styling.

7. .gitignore

This file specifies the files and directories that should be ignored by Git. Typically, this includes files like __pycache__, *.pyc, environment variables, and the SQLite database file.

8. config.py

This file contains configuration settings for the Flask application, including the SECRET_KEY for sessions and SQLALCHEMY_DATABASE_URI for the database connection.

9. Dockerfile

This file contains the instructions to build a Docker image for the application. It installs all the necessary dependencies and sets up the environment to run the Flask app within a Docker container.

Setup and Deployment

Prerequisites

  • Python 3.x
  • Flask
  • Flask-Login
  • Flask-SQLAlchemy
  • Werkzeug
  • Waitress
  • Docker (optional, for containerized deployment)

Local Setup

  1. Clone the repository:

    git clone https://github.com/yourusername/your-repo-name.git
    cd your-repo-name
  2. Set up a virtual environment (optional but recommended):

    python3 -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install the required dependencies:

    pip install -r requirements.txt
  4. Set up the database: The database will be automatically created when you first run the application.

  5. Run the application:

    python main.py
  6. Access the application: Open your browser and navigate to http://127.0.0.1:5003 to see the application in action.

Docker Setup

  1. Build the Docker image:

    docker build -t flask-app .
  2. Run the Docker container:

    docker run -d -p 5003:5003 flask-app
  3. Access the application: Open your browser and navigate to http://localhost:5003 to see the application running inside the Docker container.

Environment Configuration

The config.py file is used to manage sensitive information like the SECRET_KEY and SQLALCHEMY_DATABASE_URI. Ensure this file is properly configured before deploying the application.

Deployment Considerations

  • Security: Make sure to keep your SECRET_KEY secure and never expose it in your version control.
  • Database: The application uses SQLite by default, which is suitable for development and small-scale deployment. For production, consider switching to a more robust database like PostgreSQL or MySQL.
  • Scaling: If you need to scale this application, consider deploying it on a cloud platform like AWS, Azure, or Google Cloud, and using a managed database service.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published