File tree Expand file tree Collapse file tree 4 files changed +239
-111
lines changed
Expand file tree Collapse file tree 4 files changed +239
-111
lines changed Original file line number Diff line number Diff line change 11# FastAPI + Jinja2 Example
22
3- Warning: Python support in Workers is experimental and things will break. This
4- example is meant for reference only right now; you should be prepared to update
5- your code between now and official release time as APIs may change.
6-
73## How to Run
84
95First ensure that ` uv ` is installed:
Original file line number Diff line number Diff line change 55environment = jinja2 .Environment ()
66template = environment .from_string ("Hello, {{ name }}!" )
77
8-
9- class Default (WorkerEntrypoint ):
10- async def fetch (self , request ):
11- import asgi
12-
13- return await asgi .fetch (app , request .js_object , self .env )
14-
15-
168app = FastAPI ()
179
18-
1910@app .get ("/" )
2011async def root ():
2112 message = "This is an example of FastAPI with Jinja2 - go to /hi/<name> to see a template rendered"
@@ -33,3 +24,9 @@ async def env(req: Request):
3324 env = req .scope ["env" ]
3425 message = f"Here is an example of getting an environment variable: { env .MESSAGE } "
3526 return {"message" : message }
27+
28+ class Default (WorkerEntrypoint ):
29+ async def fetch (self , request ):
30+ import asgi
31+
32+ return await asgi .fetch (app , request .js_object , self .env )
You can’t perform that action at this time.
0 commit comments