Skip to content

Tag: django

How To give optional parameter in DRF

Hi Everyone i am created one api, where i will use [city] as first parameter to get result based on city, but i need [id] also as second parameter but [id] is optional, same time we use [id] as second parameter and sometime not, please help me out for ex- 1-get data based on city url=127.0.0.1:8000/api/car/ci…

DJango testing multiple database application

I have django application which has two database defaultdb and externdb The application works well but when testing ,this error occurs below when trying to access the extern database This error occurs which setting should I check?? Answer Change: to this: OR You can also add databases = “extern” t…

Serving file asyncronously with Django and uvicorn

I have a Django view that serves the content of a file. The Django application was running with WSGI until recently. This worked fine. Then I adapted my application to use ASGI running uvicorn. The file serving is now broken as it seems to loose the connection. How can I serve the file asynchronously with Dja…

Django – how to access request body in a decorator?

I need to access the body of a request inside of a decorator, how can i do that? I’m calling the cache_page decorator from get in a class based view. In order to perform some logic, i need to access the URL of the request in the decorator. Here is my code: Edit: i tried to do that with @wraps