<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pressing the Red Button &#187; Redirect</title>
	<atom:link href="http://www.pressthered.com/tag/redirect/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pressthered.com</link>
	<description>Adventures in Software Development</description>
	<lastBuildDate>Sun, 05 Sep 2010 16:55:12 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Redirecting to a 404 page in Django</title>
		<link>http://www.pressthered.com/redirecting_to_a_404_page_in_django/</link>
		<comments>http://www.pressthered.com/redirecting_to_a_404_page_in_django/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 07:25:28 +0000</pubDate>
		<dc:creator>jim.richmond</dc:creator>
				<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[HTTPResponse]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[Redirect]]></category>

		<guid isPermaLink="false">http://www.pressingtheredbutton.com/?p=83</guid>
		<description><![CDATA[There are a few ways to redirect to a 404 page (or page not found error) in Django. The easiest way is to raise Django&#8217;s built in 404 exception, like so:

from django.http import Http404

def myView(request, param):
  if not param:
    raise Http404

  return render_to_response('myView.html')

You can add a file called 404.html to [...]]]></description>
			<content:encoded><![CDATA[<p>There are a few ways to redirect to a 404 page (or page not found error) in Django. The easiest way is to raise Django&#8217;s built in 404 exception, like so:</p>
<pre name="code" class="python">
from django.http import Http404

def myView(request, param):
  if not param:
    raise Http404

  return render_to_response('myView.html')
</pre>
<p>You can add a file called 404.html to your templates folder and Django will use this content to display to users during 404 errors.</p>
<p>If you want something a little more raw, you could do this:</p>
<pre name="code" class="python">
from django.http import HttpResponseNotFound

def myView(request, param):
  if not param:
    return HttpResponseNotFound('&lt;h1>No Page Here&lt;/h1>')

  return render_to_response('myView.html')
</pre>
<p>By default, if a url is not found in urls.py and &#8216;DEBUG = False&#8217; in your settings.py, Django will redirect the user to a 404 page.  </p>
<p>Here is a reference for <a href="http://docs.djangoproject.com/en/dev/topics/http/views/#returning-errors">returning errors in views</a> and <a href="http://docs.djangoproject.com/en/dev/ref/request-response/">more detail on Request and Response objects</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pressthered.com/redirecting_to_a_404_page_in_django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
