0

I am having the same issue as How to pass variables with spaces through URL in :Django. I have tried the solutions mentioned but everything is returning as "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."

I am trying to pass a file name example : new 3

in urls.py:

    url(r'^file_up/delete_file/(?P<oname>[0-9A-Za-z\ ]+)/$', 'app.views.delete_file' , name='delete_file'),

in views.py:

def delete_file(request,fname):
        return render_to_response(
        'app/submission_error.html',
        {'fname':fname,
        },
        context_instance=RequestContext(request)
)

url : demo.net/file_up/delete_file/new%25203/

Thanks for the help

Community
  • 1
  • 1

2 Answers2

0

Thinking this over; are you stuck with having to use spaces? If not, I think you may find your patterns (and variables) easier to work with. A dash or underscore, or even a forward slash will look cleaner, and more predictable.

I also found this: https://stackoverflow.com/a/497972/352452 which cites:

The space character is unsafe because significant spaces may disappear and insignificant spaces may be introduced when URLs are transcribed or typeset or subjected to the treatment of word-processing programs.

You may also be able to capture your space with a literal %20. Not sure. Just leaving some thoughts here that come to mind.

Community
  • 1
  • 1
Ben Keating
  • 8,206
  • 9
  • 37
  • 37
0
demo.net/file_up/delete_file/new%25203/

This URL is double-encoded. The space is first encoded to %20, then the % character is encoded to %25. Django only decodes the URL once, so the decoded url is /file_up/delete_file/new%203/. Your pattern does not match the literal %20.

If you want to stick to spaces instead of a different delimiter, you should find the source of that URL and make sure it is only encoded once: demo.net/file_up/delete_file/new%203/.

knbk
  • 52,111
  • 9
  • 124
  • 122