Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 137ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
C

CORS

Recently created Least recently created Recently updated Least recently updated

timmy / Flask CORS 設定 (flask_cors_example.py)

Last active 6 hours ago API CORS Flask Python Security WebDevelopment

此範例使用 flask_cors 啟用跨來源資源共享 (CORS),允許不同網域的客戶端請求 Flask API,避免瀏覽器的同源政策限制,適用於前後端分離專案。

0 0 0 1
1 from flask import Flask, jsonify
2 from flask_cors import CORS
3
4 app = Flask(__name__)
5 CORS(app) # 啟用 CORS,允許跨域請求
6
7 @app.route('/api/data')
8 def get_data():
9 return jsonify({"message": "Hello, CORS is enabled!"})