django.core.urlresolvers utility functions 有四個function (Django 1.5)
不外乎因為要是url 改變,可能不只要更改url.py的maping還要修改view的redirect的位置。
所以,這裡使用了
reverse()
If you need to use something similar to the url template tag in your code, Django provides the following function:
- reverse(viewname[, urlconf=None, args=None, kwargs=None, current_app=None])
viewname is either the function name (either a function reference, or the string version of the name, if you used that form in urlpatterns) or the URL pattern name. Normally, you won’t need to worry about the urlconf parameter and will only pass in the positional and keyword arguments to use in the URL matching.
傳入 args list或者傳入 kwargs dict ,根據 view 幫你產生 url 的位置。舉例來說,
你有個view , post
>>> reverse("post",args=1200)
/post/1200
下面有個更詳細的解釋。
ref:
what is reverse() in Django - Stack Overflow
http://stackoverflow.com/questions/11241668/what-is-reverse-in-django
[转]浅谈reverse函数与django哲学 - 麻烦处... - ITeye技术网站
http://xiaolin0199.iteye.com/blog/585470
沒有留言:
張貼留言