0

Is there a way in Django to accept 'n' parameters which are delimited by a '/' (forward slash)?

I was thinking this may work, but it does not. Django still recognizes forward slashes as delimiters.

(r'^(?P<path>[-\w]+/)$', 'some.view', {}),
2
  • What do you mean by accept parameters? Commented Jul 17, 2009 at 19:57
  • 1
    The reason that doesn't work is becuase [-\w]+ includes a hyphen and \w (which is alphanumeric + underscore). You need to expand your criteria to include a /, either by adding / to the character class or by (as per Ian's answer) using something more liberal to begin with, like .* Commented Jul 17, 2009 at 20:16

2 Answers 2

3

Add the right url to your urlpatterns:

# ...
("^foo/(.*)$", "foo"), # or whatever
# ...

And process it in your view, like AlbertoPL said:

fields = paramPassedInAccordingToThatUrl.split('/')
Sign up to request clarification or add additional context in comments.

Comments

1

Certainly, Django can accept any URL which can be described by a regular expression - including one which has a prefix followed by a '/' followed by a variable number of segments separated by '/'. The exact regular expression will depend on what you want to accept - but an example in Django is given by /admin URLs which parse the suffix of the URL in the view.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.