This Repo should help you to get a simple Python website setup using the Flask framework and MySQL as a database
-
- First ensure Python is installed
- Run the command in Command Prompt (or any other shell)
python --version
- If not installed get it from here
- Run the command in Command Prompt (or any other shell)
- Enure MySQL Community Edition Is Installed
- Ensure An IDE is installed (I have given popular ones below)
- Visual Studio Code <----- the one I use
- Atom
- Pycharm
- Jupyter Notebook
- First ensure Python is installed
-
Ensure steps in To-Do are completed
-
Run the commands in Useful Stuff
-
- Download the code from this repo
- Code can be downloaded from here or by using the button above
- Extract the zip file downloaded and place the extracted folder somewhere you can remember
- Download the code from this repo
-
- Editing the MySQL util file (
util.py
)- Change line
11
inutil.py
:- The feild password should be set to the password that you created while setting MySQL server up
- The line should look like:
connection = mysql.connector.connect(host="localhost", database="demo", user="root", password="YOUR_PASSWORD_HERE", auth_plugin='mysql_native_password')
- The line should look like:
- The feild password should be set to the password that you created while setting MySQL server up
- Change line
- Editing the MySQL util file (
-
- Open your project folder in a command line
- Run the following command to start the server
- Open your project folder in a command line and run the following command:
python app.py
- Open your project folder in a command line and run the following command:
- Go to the website to see the app running
-
-
- Installing Flask and MySQL-Connector:
- Run the following command to install Flask and MySQL-Connector:
- Open your project folder in a command line and run the following command:
python -m pip install flask mysql-connector mysql-connector-python
- Open your project folder in a command line and run the following command:
- Run the following command to install Flask and MySQL-Connector:
- Installing Flask and MySQL-Connector:
-
- Creating a Database and setting it up:
- Open MySQL Command Line Client (It looks like this)
- Login Using The Password you set in setup
- Create a database called
demo
using the following command:CREATE DATABASE demo;
- Select that database to perform operations on it using the following command:
USE demo;
- Create a table called
users
in the database with the following command:-
CREATE TABLE users (id int NOT NULL AUTO_INCREMENT, username varchar(2000), password varchar(2000), uid VARCHAR(2000), PRIMARY KEY (id));
-
This command will create a tabe called users which contains the following columns:
Column Type Description id INT PRIMARY username VARCHAR-2000 - password VARCHAR-2000 - uid VARCHAR-2000 -
-
- Creating a Database and setting it up:
-
-
- CSS: W3Schools
- HTML: W3Schools
- Python: W3Schools
- Flask: Official Docs
- MySQL: MySQLTutorial