Spaces in URL for static files

61 views
Skip to first unread message

jc

unread,
Sep 11, 2012, 5:54:37 PM9/11/12
to web...@googlegroups.com
Hello,

I have a file "app/static/docs/Report 2008 12.pdf" i.e. it is in a subdir of static and the filename has spaces.
I use URL('static', 'docs', 'Report 2008 12.pdf') to generate the link.
When I click the link the browser address bar contains http://localhost:8000/static/docs/Report%202008%2012.pdf (which looks good to me) but the browser window gets "invalid request".
What am I doing wrong?

Or to re-phrase - what url should I use to serve static documents from the docs sub directory of the static directory if the filename has spaces in it? Files with no spaces in the filename work fine.

The only weird thing in my routes.py is map_hyphen = True.

Many thanks for your help.

Jonathan.

Jonathan Lundell

unread,
Sep 11, 2012, 6:02:49 PM9/11/12
to web...@googlegroups.com
By default, the router doesn't allow spaces; the default regex for static URLs is

file_match = r'([-+=@$%\w]+[./]?)+$', # legal static subpath

You can add a space if you like:

file_match = r'([-+=@$%\w ]+[./]?)+$', # legal static subpath
Reply all
Reply to author
Forward
0 new messages