0

I have this urlpath:

path('download/<str:fpath>/<str:fname>', views.download, name='download'),

And this is the view:

def download(request, fpath, fname):
    # some code

In template, I have this href tag and I want to pass those strings as arguments to the download view.

<a href="{% url 'download' 'lms/static/lms/files/homework/Math 1/3/3' 'hmm.pdf' %}">click me</a>

But I get this error:

NoReverseMatch at /

Reverse for 'download' with arguments '('lms/static/lms/files/homework/Math 1/3/3', 'hmm.pdf')' not found. 1 pattern(s) tried: ['download/(?P<fpath>[^/]+)/(?P<fname>[^/]+)\\Z']

How can I fix this?

ParsaAi
  • 293
  • 1
  • 14
  • 2
    Have you tried reducing space from first argument? Try `{% url 'download' 'x' 'y' %}` and see if you have different response. – NixonSparrow Jul 09 '22 at 07:58

1 Answers1

4

Url arguments of type str cannot contains / characters. You can see this in the error message which has translated your <str:fpath> to a regex:

tried: ['download/(?P<fpath>[^/]+)/(?P<fname>[^/]+)\\Z']

You should use a path converter for your case (see here).

For example:

path('download/<path:fpath>/<str:fname>', ...)
Nicolas Appriou
  • 2,208
  • 19
  • 32