This is a simple web application built using Flask that allows users to submit their details (name and email) via a form. It also fetches weather information from the OpenWeatherMap API and stores submitted form data in an SQLite database.
git clone https://github.com/yourusername/flask-web-app.git
cd flask-web-appInstall the required Python libraries using pip:
pip install Flask requests python-dotenvRun the init_db.py script to create the submissions table in the SQLite database.
py init_db.py.
├── app.py # Main Flask application
├── init_db.py # Script to initialize the SQLite database
├── submissions.db # SQLite database (created after running init_db.py)
├── templates
│ ├── index.html # Home page template
│ └── submissions.html # Page to display all form submissions
├── static
│ └── styles.css # Basic CSS styles for the web pages
├── .env # Environment file for storing sensitive keys
└── README.md # Project documentationAfter initializing the database, you can run the Flask web server to start the application:
py app.py/ - Home Page
Method: GET
Description: Displays the home page with the form for submitting user details (name and email) and dynamic content such as the current date/time and weather information.
Features:
- Displays weather information fetched from OpenWeatherMap API.
- Shows a form to submit user details.
- Displays success or error messages if applicable.
/submit - Form Submission
Method: POST
Description: Handles the form submission. It validates the form data and attempts to insert it into the SQLite database. If the email already exists (unique constraint), an error message will be shown.
Features:
- Inserts user details (name and email) into the database.
- Handles duplicate email submission errors and shows appropriate messages.
/submissions - View Submitted Data
Method: GET
Description: Displays a list of all form submissions from the SQLite database.
Features:
- Retrieves and displays all user submissions from the database in a tabular format.