1

I had a quick question about Django URL configuration, and I guess REGEX as well. I have a small configuration application that takes in environments and artifacts in the following way:

url(r'^env/(?P<env>\w+)/artifact/(?P<artifact>\w+)/$', 'config.views.ipview', name="bothlist"),

Now, this works fine, but what I would like to do is have it be able to have additional parameters that are optional, such as a verbose mode or no formating mode. I know how to do this just fine in the views, but I can't wrap my head around the regex.

the call would be something like

GET /env/<env>/artifact/<artifact>/<opt:verbose>/<opt:noformat>

Any help would be appreciated, thanks!

-Shawn

1 Answer 1

9

I wouldn't put such options into the URL. As you said, these are optional options, they might only change the output. They don't belong in an URL.

Your initial regex should match URLs like:

/env/<env>/artifact/<artifact>?verbose=1&noformat=1

Imho this is a much better usage of URLs

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, you are wise ;) I think this is the perfect solution, I'll wait and see what others advice but so far this seems like a winner!
+1: If it doesn't identify the requested resource, it should not be part of the URI.

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.