This documentation provides information on how to run a web application built using Flask and covers the core functionalities of your project. I will guide you step-by-step based on my own experience. You can also see the live version of the project at stayhard.com.tr.
This project aims to create a simple web application that allows users to purchase or read online books. Users log in via an email address, view books, and then buy or read them. Below, I will explain step-by-step how to run and customize the project. The core features of the project include:
- User Login
- Email Verification
- Book Viewing
- Book Purchase or Reading
- Theme and Style Options
You can run and publish your project online by following these steps:
Create a Windows virtual machine (Instance) on Amazon Web Services (AWS). This virtual machine will be used to host your project.
Use an RDP (Remote Desktop Protocol) client to access the virtual machine. Also, decrypt the password in the .PEM file to gain access.
Copy the project from your local computer to your virtual machine. This step ensures that the files containing your project's source code are transferred to your virtual machine.
Install the latest version of Python on your virtual machine. This step is necessary for your Flask application to run.
Open the command prompt on your virtual machine and navigate to your project directory. For example:
cd ProjectPath
Use the following command to start your Flask application:
python main.py
This command will run your project on your local server, making it accessible via a specific IP address and port.
To expose your Flask application running on the virtual machine to the internet, use the IP address of your virtual machine. This will be a temporary URL for your project. For example, it might be an IP address like http://51.20.1.29/.
To achieve a more professional appearance, purchase a domain from hosting.com.tr or a similar domain provider. Then, you can run your project on a custom domain by pointing it to your virtual machine's IP address.
Follow these steps to personalize the project:
- Replace
"Bearer API_KEY"in themain.pyfile with your own Shopier API key.
- Replace
"YOUR_GMAIL"and"YOUR_PASSWORD_OF_GMAIL"with your own Gmail address and password. This is used for email verification processes.
- In the
get_emailsfunction, replace"YOUR_PRODUCT_ID"with the product IDs you created in your Shopier account.
Your project is now live! You can use it by visiting your project's URL in your browser. For example, stayhard.com.tr.
The main functions of the Python code within the project are as follows:
-
User Login and Session Management
- The
Userclass is used to represent users. - The
load_userfunction is used to load users by their IDs. - Session management is provided with
login_manager.
- The
-
Fetching Email Addresses from API
- The
get_emailsfunction retrieves customer email addresses from the API and stores them in thecustomer_emailslist.
- The
-
Home Page (
/)- The
mainfunction represents the home page and returns themain.htmltemplate.
- The
-
Email Verification Process
- The
create_verification_codefunction generates a random verification code. - The
send_code_to_mailfunction sends the verification code to the user via email.
- The
-
Book Viewing and Redirection
- The
loginfunction allows the user to log in to view books. - The
check_verificationfunction checks the user's verification code and redirects them to the books.
- The
-
Book Pages
- The
firstbookandsecondbookfunctions allow the user to view the books.
- The
-
main.html: Contains the main page design. It presents a card design for the user to view books. -
login.html: Presents a form where the user can enter their email address. -
verification.html: Presents a form to enter the verification code. -
firstbook.htmlandsecondbook.html: Contain the design of the book pages. They provide a view for users to read the books. -
error_page.html: Presents a page design showing errors and warnings.
- Flask: A Python framework used for developing web applications.
- Flask-Login: A Flask extension used for user session management.
- requests: A Python module used for making API calls.
- smtplib and email: Python modules used for email verification processes.
- HTML and CSS: Basic web technologies used to create the user interface.
The project file directory is as follows:
- Bonus Project
- static
favicon.ico
main.css
pdf.css
style.css
pdf.js
pdf.worker.js
- templates
error_page.html
firstbook.html
login.html
main.html
secondbook.html
verification.html
main.py
README.md
-
main.py: The main file of the Flask application. It includes user login, email verification, book viewing, and redirection processes. -
static: The folder containing static files such as style sheets and favicon. -
templates: The folder containing the HTML templates for your Flask application.
The Python code within the project has the following functions:
- User login and session management.
- Email verification and email sending processes.
- Viewing books using API.
- User's book purchase or reading processes.