Activity 21: Python Anywhere Deployment

Fork the repository https://github.com/thirdygayares/keriderya-api

Login to PythonAnywhere

Start new console

Clone Your Forked Repository

git clone https://github.com/MonetForProgrammingPurposes/keriderya-api

Navigate to the directory

cd keriderya-api

Set Up a MySQL Database in PythonAnywhere

  • Create a new MySQL database (keriderya_db)

  • Database credentials (username, password, database name).

    Database host address:

    monette.mysql.pythonanywhere-services.com

    Username:

    monette

    password:

    password_ex

    Database name:
    keriderya_db

Create virtual environment:

python3 -m venv venv

Activate the virtual environment:

source venv/bin/activate

Manually Export Variables

If you prefer not to use the .env file, you can export the variables directly in the console:

    •       export FLASK_APP=app.py
            export FLASK_ENV=production
            export DATABASE_URL=mysql://monette:monette_08202003@monette.mysql.pythonanywhere-services.com/monette$keriderya_db
      

Edit config.py to Remove the Certificate

nano config.py

Install all the project dependencies.

pip install -r requirements.txt

Apply database migrations:

python -m flask db upgrade

Resolve Flask Compatibility Issues

  • Verify the current Flask version:

      pip show flask
    
  • If the version is 3.1.0, downgrade Flask to 1.1.4

      pip install Flask==1.1.4
    

    Upgrade Flask-SQLAlchemy

    • Update Flask-SQLAlchemy and related dependencies:

        pip install --upgrade flask-sqlalchemy
      

Check MySQL Tables

  • Verify the tables in your MySQL database:

      mysql -u monette -p
    

    SHOW TABLES;

Go to the Web Tab

  • Configure your web application.

Create a New Web App

  • Add a new web app.

  • Choose Flask as the framework.

  • Next to proceed.

Set the Virtual Environment Path

Set the path to your virtual environment by specifying the location in the Virtualenv field.

Edit WSGI configuration File

Reload the Web App

Test the App with Postman

  • Check if all endpoints are working correctly.

https://monette.pythonanywhere.com/

GitHub Forked Repository

https://github.com/MonetForProgrammingPurposes/keriderya-api