Reputation: 227
I am getting a 404 error when i am trying to show the pdf file in a new browser window when the user pushes a HTML button. I cannot see anything wring with the code.but it is not working.
Fist I show and return my path to my pdf
Views.py
def show_file(response):
pdf = open('myapp/faults.pdf', 'rb')
response = FileResponse(pdf)
return response
Urls.py
path('show_file', views.show_file),
index.html
<input type="button" value="Show Report" onclick="window.open('show_file')">
Upvotes: 2
Views: 1182
Reputation: 298
Urls.py
path('show_file/', views.show_file),
you have to put slash after your url
Upvotes: 1
Reputation: 10389
window.open()
needs a URL to open
onclick="window.open({% url 'show_file' %})"
I think that will do it.
Upvotes: 0