Skip to content

aroshmp/ISCG7444-flask-postgre

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Flask API + MySQL on Render – README

πŸ“¦ Flask API with MySQL on Render

This project is a simple Flask API that connects to a MySQL database. It supports full CRUD operations for a students table.


🧱 Step 1: Setup Project Structure

Your file structure should look like this:

.
β”œβ”€β”€ app.py
β”œβ”€β”€ .env
β”œβ”€β”€ .gitignore
β”œβ”€β”€ requirements.txt

πŸ“œ Step 2: Create .env

Create a .env file to store your sensitive credentials. Example:

DB_HOST=tcp.ap-northeast-1.clawcloudrun.com
DB_USER=root
DB_PASSWORD=Unitec123
DB_NAME=iscg7444
DB_PORT=40910

⚠️ Never commit this file to version control!


🚫 Step 3: Create .gitignore

Create a .gitignore file and include:

.venv
.env

βš™οΈ Step 4: Update app.py to Use .env

Replace hardcoded config with this:

import os
from dotenv import load_dotenv

load_dotenv()

db_config = {{
    'host': os.getenv('DB_HOST'),
    'user': os.getenv('DB_USER'),
    'password': os.getenv('DB_PASSWORD'),
    'database': os.getenv('DB_NAME'),
    'port': os.getenv('DB_PORT')
}}

πŸ“¦ Step 5: Create requirements.txt

Install packages and freeze:

pip install flask flask-cors python-dotenv mysql-connector-python
pip freeze > requirements.txt

πŸš€ Step 6: Deploy on Render

  1. Go to https://render.com and create a Web Service.
  2. Connect your GitHub repository.
  3. Choose Python environment.
  4. Set start command to:
gunicorn app:app
  1. Add environmental variables based on your .env file:
DB_HOST
DB_USER
DB_PASSWORD
DB_NAME
DB_PORT
  1. Click Deploy.

βœ… Done! Your Flask API with MySQL is now running on Render.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages