<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2.2" -->
<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/"
	>

<channel>
	<title>Rachel's Blog &#187; django</title>
	<link>http://www.willmer.com/kb</link>
	<description></description>
	<pubDate>Tue, 23 Jun 2009 16:29:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>
	<language>en</language>
			<item>
		<title>How to get at request in a template</title>
		<link>http://www.willmer.com/kb/2008/12/how-to-get-at-request-in-a-template/</link>
		<comments>http://www.willmer.com/kb/2008/12/how-to-get-at-request-in-a-template/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 15:46:36 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2008/12/how-to-get-at-request-in-a-template/</guid>
		<description><![CDATA[I needed to get at the request in a template which had been called &#8216;direct_to_template&#8217;. To make the request available, you need to modify the TEMPLATE_CONTEXT_PROCESSORS variable.
Add this to your settings file


TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
)


Then you can use {{ request }}
]]></description>
			<content:encoded><![CDATA[<p>I needed to get at the request in a template which had been called &#8216;direct_to_template&#8217;. To make the request available, you need to modify the TEMPLATE_CONTEXT_PROCESSORS variable.</p>
<p>Add this to your settings file</p>
<pre>
<code>
TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.request',
)
</code>
</pre>
<p>Then you can use {{ request }}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2008/12/how-to-get-at-request-in-a-template/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to fix &#8220;ViewDoesNotExist at /admin/&#8221;</title>
		<link>http://www.willmer.com/kb/2008/12/how-to-fix-viewdoesnotexist-at-admin/</link>
		<comments>http://www.willmer.com/kb/2008/12/how-to-fix-viewdoesnotexist-at-admin/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 12:55:33 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2008/12/how-to-fix-viewdoesnotexist-at-admin/</guid>
		<description><![CDATA[Common problem when migrating from 0.96 to 1.0&#8230;

Add &#8220;django.contrib.admin&#8221; to INSTALLED_APPS
Add &#8220;from django.contrib import admin&#8221; to urls.py
Add &#8220;admin.autodiscover()&#8221; in urls.py
Change line to (r&#8217;^admin/(.*)&#8217;, admin.site.root),

Link to relevant page in Django tutorial
]]></description>
			<content:encoded><![CDATA[<p>Common problem when migrating from 0.96 to 1.0&#8230;</p>
<ol>
<li>Add &#8220;django.contrib.admin&#8221; to INSTALLED_APPS</li>
<li>Add &#8220;from django.contrib import admin&#8221; to urls.py</li>
<li>Add &#8220;admin.autodiscover()&#8221; in urls.py</li>
<li>Change line to (r&#8217;^admin/(.*)&#8217;, admin.site.root),</li>
</ol>
<p><a href="http://docs.djangoproject.com/en/dev/intro/tutorial02/">Link to relevant page in Django tutorial</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2008/12/how-to-fix-viewdoesnotexist-at-admin/feed/</wfw:commentRss>
		</item>
		<item>
		<title>login in testing - must call GET before doing POST</title>
		<link>http://www.willmer.com/kb/2008/07/login-in-testing-must-call-get-before-doing-post/</link>
		<comments>http://www.willmer.com/kb/2008/07/login-in-testing-must-call-get-before-doing-post/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 09:28:03 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2008/07/login-in-testing-must-call-get-before-doing-post/</guid>
		<description><![CDATA[In 0.96, if you dive straight in with a POST to your login page with username/password, you&#8217;ll get a login error, saying &#8220;Your Web browser doesn&#8217;t appear to have cookies enabled. Cookies are required for logging in.&#8221;.
This is because the test cookie only gets set when you do a GET.
So doing this works:

   [...]]]></description>
			<content:encoded><![CDATA[<p>In 0.96, if you dive straight in with a POST to your login page with username/password, you&#8217;ll get a login error, saying &#8220;Your Web browser doesn&#8217;t appear to have cookies enabled. Cookies are required for logging in.&#8221;.</p>
<p>This is because the test cookie only gets set when you do a GET.</p>
<p>So doing this works:</p>
<p><code><br />
        response=client.get(login_page)<br />
        response=client.post(login_page, {'username': username, 'password': password, 'next': home_page})<br />
</code></p>
<p>But just doing the post doesn&#8217;t.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2008/07/login-in-testing-must-call-get-before-doing-post/feed/</wfw:commentRss>
		</item>
		<item>
		<title>test.Client problems logging in (now fixed)</title>
		<link>http://www.willmer.com/kb/2008/07/testclient-problems-logging-in-now-fixed/</link>
		<comments>http://www.willmer.com/kb/2008/07/testclient-problems-logging-in-now-fixed/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 12:22:53 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2008/07/testclient-problems-logging-in-now-fixed/</guid>
		<description><![CDATA[If you&#8217;re creating a test user for a unit test, do it this way:

newuser=User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')

rather than this:

newuser=User(username="john",email="lennon@thebeatles.com",password="johnpassword")

The latter looks correct, but you&#8217;ll get problems logging in since Django stores the *hash* of the password in the db, not the clear text.
Another gotcha is that the client.login() function only works with pages where you can&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re creating a test user for a unit test, do it this way:</p>
<p><code><br />
newuser=User.objects.create_user('john', 'lennon@thebeatles.com', 'johnpassword')<br />
</code></p>
<p>rather than this:</p>
<p><code><br />
newuser=User(username="john",email="lennon@thebeatles.com",password="johnpassword")<br />
</code></p>
<p>The latter looks correct, but you&#8217;ll get problems logging in since Django stores the *hash* of the password in the db, not the clear text.</p>
<p>Another gotcha is that the client.login() function only works with pages where you can&#8217;t get at them until you have logged in - if the page is available to AnonymousUser, then login() will always fail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2008/07/testclient-problems-logging-in-now-fixed/feed/</wfw:commentRss>
		</item>
		<item>
		<title>&#8216;module&#8217; object has no attribute &#8216;day_abbr&#8217;</title>
		<link>http://www.willmer.com/kb/2008/07/module-object-has-no-attribute-day_abbr/</link>
		<comments>http://www.willmer.com/kb/2008/07/module-object-has-no-attribute-day_abbr/#comments</comments>
		<pubDate>Fri, 04 Jul 2008 13:03:54 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2008/07/module-object-has-no-attribute-day_abbr/</guid>
		<description><![CDATA[This means you have a naming conflict between the core python module calendar and another one which is taking precendence.
If you&#8217;ve got your own module called calendar, rename it&#8230;
]]></description>
			<content:encoded><![CDATA[<p>This means you have a naming conflict between the core python module calendar and another one which is taking precendence.</p>
<p>If you&#8217;ve got your own module called calendar, rename it&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2008/07/module-object-has-no-attribute-day_abbr/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to access the Django request inside a Template Tag</title>
		<link>http://www.willmer.com/kb/2008/06/how-to-access-the-django-request-inside-a-template-tag/</link>
		<comments>http://www.willmer.com/kb/2008/06/how-to-access-the-django-request-inside-a-template-tag/#comments</comments>
		<pubDate>Sat, 21 Jun 2008 08:39:40 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2008/06/how-to-access-the-django-request-inside-a-template-tag/</guid>
		<description><![CDATA[You can access the Django request within a Template Tag by enabling the request context processor.
If you&#8217;re using a generic view, for example, &#8216;direct_to_template&#8217;, your render() function will then be passed a RequestContext , and you can access the request by context[&#8217;request&#8217;].
If you&#8217;re not using a generic view, and are using render_to_response(), then you have [...]]]></description>
			<content:encoded><![CDATA[<p>You can access the Django request within a Template Tag by enabling the request context processor.</p>
<p>If you&#8217;re using a generic view, for example, &#8216;direct_to_template&#8217;, your render() function will then be passed a RequestContext , and you can access the request by context[&#8217;request&#8217;].</p>
<p>If you&#8217;re not using a generic view, and are using render_to_response(), then you have to explicitly pass context_instance=RequestContext(request) as the third parameter.</p>
<p>You enable the request context processor by adding this to your settings file:</p>
<p><code>TEMPLATE_CONTEXT_PROCESSORS =  ('django.core.context_processors.request',)</code></p>
<p>You might also need to add back the default context processors. These vary from version to version - check the django documentation for the settings file for details. </p>
<p>For example, in 0.96, I&#8217;ve got this in my settings file</p>
<p><code>TEMPLATE_CONTEXT_PROCESSORS = ('django.core.context_processors.request',<br />
                               'django.core.context_processors.auth',<br />
                               'django.core.context_processors.debug',<br />
                               'django.core.context_processors.i18n',<br />
                               )<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2008/06/how-to-access-the-django-request-inside-a-template-tag/feed/</wfw:commentRss>
		</item>
		<item>
		<title>&#8220;AttributeError: &#8216;module&#8217; object has no attribute &#8216;blah&#8217;&#8221;</title>
		<link>http://www.willmer.com/kb/2007/12/attributeerror-module-object-has-no-attribute-blah/</link>
		<comments>http://www.willmer.com/kb/2007/12/attributeerror-module-object-has-no-attribute-blah/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 15:05:47 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2007/12/attributeerror-module-object-has-no-attribute-blah/</guid>
		<description><![CDATA[
The obvious cause of this is that the settings.py doesn&#8217;t have the directory containing blah listed in INSTALLED_APPS.
A less obvious cause: you&#8217;ll also get this error if the directory doesn&#8217;t contain a file __init__.py.

]]></description>
			<content:encoded><![CDATA[<ul>
<li>The obvious cause of this is that the settings.py doesn&#8217;t have the directory containing blah listed in INSTALLED_APPS.</li>
<li>A less obvious cause: you&#8217;ll also get this error if the directory doesn&#8217;t contain a file __init__.py.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2007/12/attributeerror-module-object-has-no-attribute-blah/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Django GeoIP templatetag</title>
		<link>http://www.willmer.com/kb/2006/10/django-geoip-templatetag/</link>
		<comments>http://www.willmer.com/kb/2006/10/django-geoip-templatetag/#comments</comments>
		<pubDate>Fri, 27 Oct 2006 18:17:26 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2006/10/django-geoip-templatetag/</guid>
		<description><![CDATA[I&#8217;ve published 2 template tags for use with GeoIP at geoip.py.
Hope they may be of use&#8230;
Usage:
# Templatetag get_country_name returns the client&#8217;s country code
#
# Example:
# {% ifequal get_country &#8220;GB&#8221; %}
#       do something
# {% endifequal %}
# Templatetag get_country sets the given variable name
# to the client&#8217;s country code
#
# Example:
# {% get_country [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve published 2 template tags for use with GeoIP at <a title="geoip.py" href="http://www.willmer.org/html/djangocode/geoip.py">geoip.py.</a></p>
<p>Hope they may be of use&#8230;</p>
<p>Usage:</p>
<p># Templatetag get_country_name returns the client&#8217;s country code<br />
#<br />
# Example:<br />
# {% ifequal get_country &#8220;GB&#8221; %}<br />
#       do something<br />
# {% endifequal %}</p>
<p># Templatetag get_country sets the given variable name<br />
# to the client&#8217;s country code<br />
#<br />
# Example:<br />
# {% get_country as my_country %}<br />
# {% ifequal my_country &#8220;GB&#8221; %}<br />
#       do something<br />
# {% endifequal %}</p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2006/10/django-geoip-templatetag/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Django/Ajax: a great simple tutorial</title>
		<link>http://www.willmer.com/kb/2006/10/djangoajax-a-great-simple-tutorial/</link>
		<comments>http://www.willmer.com/kb/2006/10/djangoajax-a-great-simple-tutorial/#comments</comments>
		<pubDate>Fri, 27 Oct 2006 17:56:14 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2006/10/djangoajax-a-great-simple-tutorial/</guid>
		<description><![CDATA[An excellent tutorial from James Bennett for your first step into combining AJAX with Django
&#8220;A step-by-step walk through a simple AJAX form with Django backend&#8221;
]]></description>
			<content:encoded><![CDATA[<p><a title="A simple AJAX example" href="http://www.b-list.org/weblog/2006/07/31/django-tips-simple-ajax-example-part-1">An excellent tutorial </a>from James Bennett for your first step into combining AJAX with Django</p>
<p class="description"><cite>&#8220;A step-by-step walk through a simple AJAX form with Django backend&#8221;</cite></p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2006/10/djangoajax-a-great-simple-tutorial/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How to make a Django ForeignKey optional</title>
		<link>http://www.willmer.com/kb/2006/10/how-to-make-a-foreign-key-optional/</link>
		<comments>http://www.willmer.com/kb/2006/10/how-to-make-a-foreign-key-optional/#comments</comments>
		<pubDate>Fri, 06 Oct 2006 11:12:23 +0000</pubDate>
		<dc:creator>Rachel</dc:creator>
		
		<category><![CDATA[django]]></category>

		<guid isPermaLink="false">http://www.willmer.com/kb/2006/10/how-to-make-a-foreign-key-optional/</guid>
		<description><![CDATA[Looks like you need to have both blank=True and null=True to make a ForeignKey optional in a django model&#8230;
]]></description>
			<content:encoded><![CDATA[<p>Looks like you need to have both <code>blank=True</code> and <code>null=True</code> to make a ForeignKey optional in a django model&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.willmer.com/kb/2006/10/how-to-make-a-foreign-key-optional/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
