grantmcconnaughey
grantmcconnaughey

Reputation: 10689

Using ViewerJS with Django

I am trying to use ViewerJS in a Django 1.8.2 application. However, the link I am using will not render the PDF. I have the ViewerJS folder under static/js/ and my PDF under static/pdf/docs/. Here is the link I'm using:

<a href="/static/js/ViewerJS/#/static/pdf/docs/agreement.pdf" class="btn">Preview</a>

The error I am receiving is a 404. Django passes back an error message "Directory indexes are not allowed here.".

Request Method: GET
Request URL:    http://localhost:8000/static/js/ViewerJS/
Raised by:  django.contrib.staticfiles.views.serve

If I go to localhost:8000/static/pdf/docs/agreement.pdf in my browser then the PDF downloads just fine. If I go to localhost:8000/static/js/ViewerJS/pdf.js then the pdf.js file downloads just fine. So I'm not sure why it isn't working.

Upvotes: 3

Views: 1481

Answers (2)

I have just the same problem. I am trying to access a file located at static/gutenberg/docs/files/something.pdf in Django

The url I created is

"http://localhost:8000/static/gutenberg/js/ViewerJS/index.html/#/static/gutenberg/docs/files/something.pdf".

Inspite of adding index.html to the complete it wouldn't work.I am not sure why.

The path is right because I am able to download the file when I run "/static/gutenberg/docs/files/something.pdf" on my browser.

Upvotes: 0

Daniel Roseman
Daniel Roseman

Reputation: 599610

Django's static server is only for development, and is purposely limited. As the error says, it doesn't deal with directory indexes.

You could probably make this work by making the link go directly to /static/js/ViewerJS/index.html.

Upvotes: 3

Related Questions