How to make a url pattern that catch any url ?

344 views
Skip to first unread message

Loai Ghoraba

unread,
Nov 28, 2012, 3:10:00 PM11/28/12
to django...@googlegroups.com
Hi

I am serving some files, and I want whenever I have a url :/download/path/to/some/file to map this to a view function with path/to/some/file sent as a parameter of the function, so how could I accomplish that ?

I want a url of the following schema :
    url(r'downloads/(?P<path>\[Anything including backslashes])$', 'download_file'),

Thanks a lot.

Loai Ghoraba

unread,
Nov 28, 2012, 3:19:26 PM11/28/12
to django...@googlegroups.com
I just go it, it is 
 
url(r'^download/(?P<path>.*)$', 'faculty.views.Main.download_file'),

Thanks :)



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/_cVverOl0AoJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Tim Chase

unread,
Nov 28, 2012, 3:28:09 PM11/28/12
to django...@googlegroups.com, Loai Ghoraba
On 11/28/12 14:19, Loai Ghoraba wrote:
> I just go it, it is
>
> url(r'^download/(?P<path>.*)$', 'faculty.views.Main.download_file'),

Just be careful to normalize the resulting path so that people don't
do things like

http://example.com/download/../../etc/passwd

Fortunately, the standard library has functions in os.path.* for
getting the absolute path, checking against leading subdirectory
paths, and the like.

-tkc


Loai Ghoraba

unread,
Nov 28, 2012, 3:31:50 PM11/28/12
to Tim Chase, django...@googlegroups.com
thanks for the important advise :)
Reply all
Reply to author
Forward
0 new messages