Solution 1 :

I had the same problem. If you can navigate to the project.publications_pdf.url in your browser and your pdf is displayed, then it is likely to be an issue when rendering the frame, add

X_FRAME_OPTIONS = 'SAMEORIGIN'

to settings.py

If when you navigate to project.publications_pdf.url in your browser you also do not see the pdf then your pdf is not being served from your media folder. Make sure in your main urls.py you are able to serve your media files, i.e. include,

from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
    your current paths,
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Problem :

I have stored a pdf in my media folder and would like to embed it in my template. It says ‘127.0.0.1 is blocked’ and ‘127.0.0.1 refused to connect’.

My HTML code:

<embed src="{{ project.publications_pdf.url }}" type="application/pdf" height="700px" width="500px">

The url is stored in the Project model as publications_pdf.

Comments

Comment posted by stackoverflow.com/questions/291813/…

stackoverflow.com/questions/291813/…

By