-
Privileged issue
Issue Contentfrom fastapi import FastAPI, Request, Path
from pydantic import ConfigDict
from core import settings
app = FastAPI()
@app.get("/{url:path}", response_class=str)
async def frontend_page(request: Request, url: str = Path(..., pattern=f"^(?!/api/).*")):
return "success"
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host=settings.OPENAPI_HOST, port=7791)Python、Pydantic versionspydantic version: 2.7.3 code error detailsDuring handling of the above exception, another exception occurred: Traceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
Is there any way to fix this? I have the same issue and cannot find a way around |
Beta Was this translation helpful? Give feedback.
-
|
If you want your url to start with import re
...
@app.get("/{url:path}")
async def frontend_page(request: Request, url: str = Path(..., pattern=re.compile(f"^(?!/api/).*"))):
... |
Beta Was this translation helpful? Give feedback.
-
|
What has changed fairly recently in FastAPI (starting in v0.113.0) is what appears to be FastAPI no longer respecting |
Beta Was this translation helpful? Give feedback.
-
|
should |
Beta Was this translation helpful? Give feedback.
If you want your url to start with
/api/, you just need to change the pattern to"^api/.+".But if your pattern(regex) must contain
(?, you can usere.compile():