In my view, I want to redirect to a URL (which points to a hosted image) but also add the User-Agent header to that GET request (to avoid 403 errors). I've explored two options:
- The
redirect(url)Django function. Is there a way to somehow add on headers? Using the
requestslibrary:r = requests.get(picture.url, headers={'User-Agent': user_agent,})But then what should I return from my view?
return r,return r.contentorreturn json()didn't work for me.
== EDIT AFTER DUPLICATE QUESTION SOLUTION ==
As suggested, I tried the solution as shown here:
def my_view(request):
response = redirect("www.somewebsite.com/image.png")
response['User-Agent'] = "Mozilla..."
return response
But that didn't help with the 403 error when fetching image.png. I want to make sure that headers are added to the GET request fetching the image, not to the response returned by the view.
Thanks!