- Set up your development environment:
Install Python and pip if you haven't already. Then, create a new directory for your project and set up a virtual environment:
Install Node JS
https://nodejs.org/en/download/package-manager
mkdir flask-vercel-app
cd flask-vercel-app
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate- Install Flask:
Go to your terminal and install Flask using the below command.
pip install FlaskCreate a github project in git and clone that project to you local
- Create your Flask application:
Create a file named index.py in your project directory with the following content:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Hello, World!"
if __name__ == "__main__":
app.run()- Create a
requirements.txtfile by running this command in the same terminal:
pip freeze > requirements.txt- Create a
vercel.jsonconfiguration file:
Create a file named vercel.json in your project directory with the following content:
{
"version": 2,
"builds": [
{
"src": "./index.py",
"use": "@vercel/python"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "/"
}
]
}- Test your application locally:
python index.pyVisit http://localhost:5000 in your browser to see your app running.
- Set up version control (optional but recommended):
Initialize a Git repository and commit your changes:
git init
git add .
git commit -m "Initial commit"- Deploy to Vercel:
First, install the Vercel CLI:
npm install -g vercelThen, deploy your application:
vercelFollow the prompts to log in or create a Vercel account if you haven't already. Choose the appropriate project settings when prompted.
- Access your deployed application:
After the deployment is complete, Vercel will provide you with a URL where your application is live. You can visit this URL to see your Flask app running on Vercel.
- For future updates:
Whenever you make changes to your application, you can redeploy by running:
vercel --prod