We ended our last session with the Python app all setup on GoDaddy. Now we will continue our work and setup the python environment with all of the packages that we need to run our Flask-API app. To enter the python environment that was created you need to go the Web Application page that was created and grab the text that is presented.
There are two ways of getting to the Terminal in GoDaddy. You can open up a terminal on your local machine or you can open one up through the cPanel Main Page as shown below.
When your terminal opens you can paste the text from the application page into it and run the command.
This will put you in the right Environment and Directory to do a Pip install of the packages needed. Below is a screen shot of all the packages that need to be installed.
Here is an easy list of the packages to install.
pip install flask
pip install sqlalchemy
pip install flask_sqlalchemy
pip install pymysql
pip install marshmallow
pip install flask-marshmallow
pip install marshmallow-sqlalchemy
Once those are installed you should get a listing of everything install like above. From here you will need to add your code to the app.py file in your application directory. You can copy and paste the code from pt into your app.py file and then make these changes to it.
Add an import for pymysql
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://username:password@localhost/dbname'
You should notice the addition of “+pymysql” here is different from the original code.
# Init schema product_schema = ProductSchema() products_schema = ProductSchema(many=True)
The above is a change also. I had to remove the strict=true from the product_schema and the products_schema
The last thing I need to do was create the database. The first time I ran the code it created the tables and populated the data with the json that I fed it through Postman.
I hope this helps you get started with Python on GoDaddy. If you have any questions drop them in the comments.