开发者

Alternative to hardcode urls in views

In my views I sometimes use this:

return HttpResponseRedirect("/account/")

But that is hardcoding a url in my view, which I think is not very nice.

So what is the alternative? I know I can generate urls directly from the urls.py file, in my templates, via the {% url %} tag, so th开发者_如何转开发ere has to be something I can do in my views, right?


You use the reverse function. Documentation here: reverse


Yes, use the reverse function, but it is even better if used together with a URL pattern name

See http://docs.djangoproject.com/en/dev/topics/http/urls/#id2

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜