Hosting a Flask Application on Square Cloud
This article guides you through creating and hosting a Flask application on Square Cloud.
Creating a New Flask Project
- Before getting started, make sure you have Python and pip installed on your system. If you don’t already have them, you can download them from the official Python website and official Pip website.
- Next, you will need to create an account on Square Cloud, which can be done through the sign up page. You can use your email to create an account.
- Finally, you need to have an active paid plan on your account. You can view our plans and purchase one according to your needs here.
With Python and pip installed, you can create a new Flask project. First, install Flask using pip:
Then, create a new Python file (e.g., app.py
) and add the following code to create a basic Flask application:
Configuring the Production Environment with Waitress
In the above code, we create a basic route that returns “Hello, World!” when accessed. The application is configured to run on port 80, which is the default port for HTTP traffic.
Managing Dependencies with the requirements.txt file
The requirements.txt
file is a file that lists all external libraries required for your project. You should list all libraries your project will use, excluding native libraries like random
and datetime
. This file should be included when submitting your application to Square Cloud.
Creating the squarecloud config file
Learn about: how to make the configuration file for Square Cloud.
The squarecloud.app file is a configuration file that will be used to configure your application; it will be used to define the name, description, version, main file, among other things.
Configuring the START Field
In the Square Cloud configuration file, the START field is optional and is only necessary if you are using a custom script to start the website or API. In the example provided, the START field is not necessary.
Purchasing a Plan Before Uploading Your Project
Before you can upload your project to Square Cloud, it’s important to understand that you need to purchase a plan. The type of plan you choose will depend on the resources required by your application. You can view our plans here.
Uploading Project to Square Cloud
After preparing your project files, you can now upload them to Square Cloud and host your project.
Access the Square Cloud Dashboard and upload your project files.
Access the Square Cloud Dashboard and upload your project files.
First Step
First, you need to have the CLI installed in your environment. If you don’t have it yet, run the following command in your terminal:
If you already have it, we recommend updating it. To do this, run the following command in your terminal:
Second Step
Now, to authenticate and use other CLI commands, you will find your authorization key here by clicking on “Request API Key”. After obtaining your authorization key, run the following command:
Third Step
Finally, to deploy your application to Square Cloud using the CLI, you need to execute the following command, passing the path of your zip file:
Troubleshooting
Custom Domain
Custom Domain
If you want to use a custom domain for your application hosted on Square Cloud, note that by default, the URL will be something like https://mysite.squareweb.app/
. The subdomain is determined by the SUBDOMAIN field in the configuration file. However, if you prefer to use a custom domain, such as mysite.com
, you’ll need to purchase the Standard
plan or a higher plan. We detail each step to set up your custom domain in our article: How to Set Up Your Custom Domain.
Minimum RAM Requirements
Minimum RAM Requirements
The minimum amount of RAM required to host a website or API is 512MB. However, depending on the size and complexity of your Flask application, it may be advisable to use a larger amount of RAM to avoid the LACK_OF_RAM error.
Temporary Access Denied
Temporary Access Denied
If you receive the message “Your access has been temporarily denied.” when trying to access the site, please wait for some time. If the issue persists, feel free to contact us at https://squarecloud.app/dashboard/support.
Website took too long to respond...
Website took too long to respond...
If you receive the message “Website took too long to respond…” make sure you have correctly set port 80 on your application. If the issue persists, feel free to contact us at https://squarecloud.app/dashboard/support.
Additional Resources
For more information about Flask and its tools, visit the official Flask documentation. There, you’ll find detailed guides, tutorials, and API documentation to help you make the most out of Flask.
If you continue to experience any issues, please don’t hesitate to contact our support team.