In this tutorial, I am going to walk through the basics of setting up and deploying a flask app from scratch using WayScript (a free deployment platform).
Step 1 - Create a WayScript project.
WayScript projects are referred to as lairs, these are just flexible cloud based development environments for you to run and test your code.
Step 2 - Open up the code editor
Click on the develop tab to open your code editor on WayScript. In the editor, you have the following panels:
- Editor
- Terminal
- Triggers
- Processes
I'll cover some of these but for now make sure you have the Editor
and Terminal
views open (like in the image above).
Step 3 - Install Flask
In the Terminal
, input the following two commands:
pip install flask
pip freeze > requirements.txt
Step 4 - Setup Your Files
Now, we are going to add the first file for building your server. In the Terminal
, type the following command:
touch app.py
Once done, you should see the file app.py
appear in the Code Editor.
Step 5 - Edit your app.py
File
Here is the initial code for your app.py file:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return {"Message" : "Hello World"}
Step 6 - Set Up Your Deployment
In order to deploy your app, you need to configure an deploy Trigger.
In your Triggers
panel, select a Deploy trigger and fill in the following details:
Command To Run: flask run --port 8080 --host 0.0.0.0
Port: 8080
Step 7 - Deploy your app!
Once the Trigger
is set up, go the Deploy
tab and press deploy! Now you app is good to go. You can view the app by referencing the URLs in your Endpoints
tab.
Under endpoints, hit the prod url to see your endpoint working!
Note - in order to run your server in the dev mode, you must press the play button on the trigger you set up
Other Notes - Built in logs, processes, and alerts
There are other tabs for viewing logs, your server running, and you can set up automatic alerting if your app has any errors.
Happy coding!
Top comments (0)