Agent skill · Frontend

配置支持CORS和图片服务的Flask后端API

用于配置Flask后端以适配React前端,解决跨域问题,处理JSON请求,并通过HTTP路由提供生成的图片资源。

ECNU-ICALKgithub.com/ECNU-ICALKGitHub ↗
claude-code
Install
npx skills add ECNU-ICALK/AutoSkill --skill 配置支持cors和图片服务的flask后端api --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 1
SKILL.md size: 2 KB
Bundled scripts: none
Version: 0.1.0
Path: SkillBank/ConvSkill/chinese_gpt4_8/配置支持cors和图片服务的flask后端api/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 539
Language: Python

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# 配置支持CORS和图片服务的Flask后端API 用于配置Flask后端以适配React前端,解决跨域问题,处理JSON请求,并通过HTTP路由提供生成的图片资源。 ## Prompt # Role & Objective 你是一个Flask后端开发专家。你的任务是根据React前端的需求,配置Flask后端API,解决跨域资源共享(CORS)问题,正确处理JSON数据请求,并安全地提供生成的图片资源。 # Operational Rules & Constraints 1. **CORS配置**:必须使用 `flask_cors` 扩展。在创建Flask应用后,立即调用 `CORS(app)` 以允许所有来源的跨域请求(或根据安全需求配置特定来源)。 2. **JSON数据处理**:针对React前端使用 `axios.post` 发送的数据(Content-Type通常为application/json),后端路由函数中必须使用 `request.get_json()` 来获取参数,严禁使用 `request.form`,否则会导致400 Bad Request或KeyError。 3. **前后端分离架构**:如果前端是独立部署的React应用(前后端分离),后端代码中不应包含 `render_template` 的主页路由(如 `@app.route('/')`),后端应仅作为API服务器运行。 4. **图片/文件服务路由**: - 当后端调用外部服务(如Gradio)生成文件并返回本地路径时,严禁直接将该本地路径返回给前端(浏览器会阻止 `file://` 协议)。 - 必须创建一个专门的GET路由(例如 `@app.route('/image/<path:filename>')`),使用 `send_from_directory` 从指定目录发送文件。 - 返回给前端的数据必须是该路由的完整HTTP URL,使用 `url_for('get_image', filename=filename, _external=True)` 生成。 5. **参数校验**:在处理请求前,检查 `request.get_json()` 获取的参数(如description, style等)是否完整,若缺失则返回400错误及相应的错误信息。 # Anti-Patterns - 不要在前后端分离的架构中保留 `render_template('index.html')`。 - 不要在接收JSON请求时使用 `request.form` 或 `request.args`。 - 不要将本地文件系统路径(如 `C:/Users/...`)直接作为API响应返回给前端。 ## Triggers - Flask React跨域问题 - Flask后端配置CORS - F

What's inside
Steps it walks through
  1. Prompt
  2. Triggers
More from AutoSkill
All skills →
About this skill
What does the 配置支持CORS和图片服务的Flask后端API skill do?

用于配置Flask后端以适配React前端,解决跨域问题,处理JSON请求,并通过HTTP路由提供生成的图片资源。

How do I install it?

Run `npx skills add ECNU-ICALK/AutoSkill --skill 配置支持cors和图片服务的flask后端api --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From ECNU-ICALK/AutoSkill, a repository with 539 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going