Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

my-vercel-flask-example

这是一个最小的 Flask 单页网站示例,演示如何将静态单页由 Flask 提供并部署到 Vercel(使用 @vercel/python 构建器)。

项目结构(相关文件):

  • api/index.py — Flask 应用(根路径渲染 templates/index.html,兼容 Vercel 的 Python builder)
  • templates/index.html — 单页网站的 HTML 模板
  • requirements.txt — 依赖清单(Flask)
  • vercel.json — Vercel 部署配置

本地运行

  1. 创建并激活虚拟环境(可选,但推荐):
python3 -m venv .venv
source .venv/bin/activate
  1. 安装依赖:
pip install -r requirements.txt
  1. 运行本地服务:
python api/index.py

打开浏览器访问 http://localhost:5000/ 将看到单页网站 (HTML),或访问 http://localhost:5000/json 获取 JSON 示例响应。

部署到 Vercel

  1. 安装 Vercel CLI(如果尚未安装):
npm i -g vercel
  1. 登录并部署(交互式):
vercel login
vercel

或直接生产部署:

vercel --prod

Vercel 会使用 vercel.json 中指定的 @vercel/python 构建器来安装 requirements.txt 中的依赖并将 api/index.py 作为 Serverless Function / WSGI 应用服务。

注意:如果 Vercel 的运行时或 builder 有更新,请参考 Vercel 官方文档以获取最新的 Python 部署指引。

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages