I am trying to load a pdf file in django which is already present in the database. I can access the pdf file using the url, "localhost:8000/documents/file.pdf" but when I perform the query and return the response containing this file, url it redirects to "localhost:8000/ans/documents/file.pdf" which doesn't exist. The html code is:
<form id="signup-form" method="POST" action="ans/">
{% csrf_token %}
<input type="text" name="id" id="id" placeholder="Report id" />
<input type="submit" value="Check" />
</form>
The path in urls.py is
path('ans/',views.func),
The view is:
def func(request):
if request.method=="POST":
id=request.POST.get("id")
ans = query.objects.get(id=id)
response=ans.repo
if ans is None:
return render(request,"index.html",{})
else:
return redirect(response)
The bottomline is, I wan't to get rid of the "/ans/" in the url.