<?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>treibsand.com &#187; Generic Views</title>
	<atom:link href="http://www.treibsand.com/tag/generic-views/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.treibsand.com</link>
	<description></description>
	<lastBuildDate>Tue, 27 Dec 2011 12:46:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Ärger mit Generic Views von Django</title>
		<link>http://www.treibsand.com/2009/03/09/arger-mit-generic-views-von-django/</link>
		<comments>http://www.treibsand.com/2009/03/09/arger-mit-generic-views-von-django/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 10:16:12 +0000</pubDate>
		<dc:creator>Toast</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[Generic Views]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.treibsand.com/?p=285</guid>
		<description><![CDATA[Django ist ja eines der besten Frameworks für Python um schnell Webanwendungen zu realisieren. Allerdings ist es leider noch nicht so ausgereift wie z.B. Ruby on Rails. Die Generic Views von Django sind zwar sehr hilfreich, allerdings nicht ganz konsequent umgesetzt. So gibt es bei den Views create\_object, update\_object und delete\_object die Möglichkeit login\_required zu [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.djangoproject.com">Django</a> ist ja eines der besten Frameworks für Python um schnell Webanwendungen zu realisieren. Allerdings ist es leider noch nicht so ausgereift wie z.B. Ruby on Rails. Die Generic Views von Django sind zwar sehr hilfreich, allerdings nicht ganz konsequent umgesetzt.</p>
<p><span id="more-285"></span><br />
So gibt es bei den Views <b>create\_object</b>, <b>update\_object</b> und <b>delete\_object</b> die Möglichkeit <b>login\_required</b> zu übergeben, aber bei anderen Views wie z.B. <b>direct\_to\_template</b> nicht. Das ist ziemlich ärgerlich, da es hier genauso Sinn machen würde.</p>
<p>Allerdings gibt es einen kleinen Workaround&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">contrib</span>.<span style="color: black;">auth</span>.<span style="color: black;">decorators</span> <span style="color: #ff7700;font-weight:bold;">import</span> login_required 
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">views</span>.<span style="color: black;">generic</span>.<span style="color: black;">simple</span> <span style="color: #ff7700;font-weight:bold;">import</span> direct_to_template
&nbsp;
urlpatterns = patterns<span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span>,
	<span style="color: black;">&#40;</span>r<span style="color: #483d8b;">'^meineurl/$'</span>,login_required<span style="color: black;">&#40;</span>direct_to_template<span style="color: black;">&#41;</span>,
		<span style="color: black;">&#123;</span><span style="color: #483d8b;">'template'</span>:<span style="color: #483d8b;">'welcome.html'</span><span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>,
...</pre></div></div>

<p>Dadurch erhält man das gleiche Ergebnis, wie wenn man <b>login\_required</b> als Argument dem View übergibt.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.treibsand.com/2009/03/09/arger-mit-generic-views-von-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

