tags:

views:

92

answers:

2

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 there has to be something I can do in my views, right?

+8  A: 

You use the reverse function. Documentation here: reverse

Paolo Bergantino
+1  A: 

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

gbsmith