Replies: 6 comments
-
|
I'm not familiar with Django but this seems like something you should be able to fix within Django. And I'm not really sure how you think this is going to work. You have an async FastAPI function calling a Django API route in the background after it's returned its response, where do you suppose the file should end up? And how should this resolve the problems you've had with Django? There's a |
Beta Was this translation helpful? Give feedback.
-
|
thanks @Hultner you mentioned to not use another framework, but StreamingHttpResponse is in starlette.responses which is not in Django, so just try and pip3 install starlette without fastapi? |
Beta Was this translation helpful? Give feedback.
-
I was referring to from Now if you regardless would like to use them both in conjunction, for instance if you plan to migrate to FastAPI for newer things going forward then you could do that by mounting the WSGI-application in your FastAPI app using the |
Beta Was this translation helpful? Give feedback.
-
|
Hi again @Hultner it is not just this, but within this particular Django project there are a number of timeout issues, not just this one, and also in Starlette there is also a FileResponse as this is a download timeout, maybe slightly more appropriate than the StreamingResponse in this case? Yes I saw we need this WSGIMiddleware should both framework are needed. Or simpler just to serve existing Django with ASGI server like uvicorn or Hypercorn and move existing functions into Django 3.1+ async functions? |
Beta Was this translation helpful? Give feedback.
-
I’m not familiar enough with Django to answer that. About the timeouts, it must be possible to configure django, or the server you’re serving the django content with to allow for longer timeouts. As for FileResponse that’s for serving static file directly, not for ones generated dynamically in runtime. If you are serving static files you should probably use a static file server like nginx or something like WhiteNoise if you want to keep it in Python. |
Beta Was this translation helpful? Give feedback.
-
|
@scheung38 you have a few options here:
In my opinion, FastAPI isn't the right choice for your use-case. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Original Django file to work with large excel files:
If so how do we integrate FastAPI into existing Django project as I see there are a few config settings needed.
How do we tell Django not to call work_file directly but from FastAPI?
or simply rename work_file into fastapi_work_file and work_file so Django calls the same work_file function but delegates background with new function:
But this work_file changes to a different input arguments of background_tasks instead of the original request, key
or define BackgroundTasks locally inside FastAPI function?
I imagine localhost:8000/docs to show endpoints from FastAPI on top of existing localhost:8000/swagger from Django without any conflict
Description
Environment
To know the FastAPI version use:
python -c "import fastapi; print(fastapi.__version__)"To know the Python version use:
Python 3.9.5
Additional context
Beta Was this translation helpful? Give feedback.
All reactions