开发者

Django URL regex question

开发者 https://www.devze.com 2022-12-23 14:53 出处:网络
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:

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.开发者_JAVA技巧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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消