WSGI'yi Dahil Etme - Flask, Django ve Diğerleri¶
🌐 Translation by AI and humans
This translation was made by AI guided by humans. 🤝
It could have mistakes of misunderstanding the original meaning, or looking unnatural, etc. 🤖
You can improve this translation by helping us guide the AI LLM better.
WSGI uygulamalarını Sub Applications - Mounts, Behind a Proxy bölümlerinde gördüğünüz gibi mount edebilirsiniz.
Bunun için WSGIMiddleware'ı kullanabilir ve bunu WSGI uygulamanızı (örneğin Flask, Django vb.) sarmalamak için kullanabilirsiniz.
WSGIMiddleware Kullanımı¶
WSGIMiddleware'ı import etmeniz gerekir.
Ardından WSGI (örn. Flask) uygulamasını middleware ile sarmalayın.
Ve sonra bunu bir path'in altına mount edin.
from a2wsgi import WSGIMiddleware
from fastapi import FastAPI
from flask import Flask, request
from markupsafe import escape
flask_app = Flask(__name__)
@flask_app.route("/")
def flask_main():
name = request.args.get("name", "World")
return f"Hello, {escape(name)} from Flask!"
app = FastAPI()
@app.get("/v2")
def read_main():
return {"message": "Hello World"}
app.mount("/v1", WSGIMiddleware(flask_app))
Kontrol Edelim¶
Artık /v1/ path'i altındaki her request Flask uygulaması tarafından işlenecektir.
Geri kalanı ise FastAPI tarafından işlenecektir.
Eğer uygulamanızı çalıştırıp http://localhost:8000/v1/ adresine giderseniz, Flask'tan gelen response'u göreceksiniz:
Hello, World from Flask!
Ve eğer http://localhost:8000/v2 adresine giderseniz, FastAPI'dan gelen response'u göreceksiniz:
{
"message": "Hello World"
}