0

I am stuck trying to pass a parameter to a PDF rendered in the browser from Django. I think I want to serve the pdf with #page=[page_num] appended to the url the browser sees it at.

This is my attempt at doing this in urls.py (note that I'm still on Django 1.11.4 and so haven't migrated to re_path for these url patterns):

url(r'^files/(?P<path>.*)#page=[(?P<page_num>d+)]$', serve, {'document_root' : settings.MEDIA_ROOT}, name='file_url')

This is the link in the template:

  <object id="pdf" width="100%" height="900" data="{% url 'knowledge_manager:file_url' document.ref_file.name document.last_open_page %}" type="application/pdf" > 
  </object>

The associated view for the whole page is a generic.DetailView.

The error I'm getting is a 'no reverse match' for two parameters aimed at a two-field r.e.

`Reverse for 'file_url' with arguments '('documents/AutonomyinEvolution.pdf', 4)' not found. 

1 pattern(s) tried: ['knowledge_manager/files/(?P.*)#page=[(?Pd+)]$'] `

It was working fine before I tried to add the page number. Is it worth persisting with this approach or is doing it with say javascript more realistic?

Atcrank
  • 439
  • 3
  • 11
  • Maybe try this: 1) [Render a templated view of the PDF.](https://django-easy-pdf.readthedocs.io/en/develop/index.html) 2) In the html of that view, link to the page on load using [javascript](https://stackoverflow.com/a/34230090/9155312). – wrabbit Feb 14 '18 at 06:03
  • Try to render it using Javascript more than a pythonic way – A.Raouf Feb 14 '18 at 06:04

0 Answers0