On Dec 4, 8:37 am, chefsmart <moran.cors...@gmail.com> wrote:
> According to the docs 
> athttp://docs.djangoproject.com/en/dev/topics/http/shortcuts/#render-to...
> the render_to_response shortcut "Renders a given template with a given
> context dictionary and returns an HttpResponse object with that
> rendered text."
>
> The HttpResponse object have a default status=200 (http://
> docs.djangoproject.com/en/dev/ref/request-response/#id3)
>
> How can I use the render_to_response to return HTTP status codes other
> than 200?
>
> Can render_to_response return HttpResponse subclasses like
> HttpResponseRedirect, HttpResponseForbidden etc instead of the simple
> HttpResponse?

You can, if you really want to. The only difference between
HttpResponse and HttpResponseForbidden is the status_code, so you can
just set the status_code attribute on the result of render_to_response
(which is an HttpResponse) to whatever you want.

However, I can't for the life of me think why you'd want to do this.
render_to_response is used, as the name implies, to render a template
and return it as an HttpResponse. In the case of 404 and 301 etc you
don't need a template, surely.
--
DR.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to