    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>vaporbase :: Rails and Django - Routing and Controllers (part 7/15)</title>
        <link>http://www.vaporbase.com/</link>
        <description>the knowledge base that almost is</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Vaporbase Admin</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:admin@parkerhill.com" /> 
       <sy:updatePeriod>hourly</sy:updatePeriod> 
       <sy:updateFrequency>1</sy:updateFrequency> 
       <docs>http://backend.userland.com/rss</docs>

<!-- show a header for the current publication type -->
        <h2>Postings</h2>


<div class="xar-mod-head"><span class="xar-mod-title">rails + django</span></div>

<table border="0" cellpadding="1" cellspacing="0">
<tr>
    <td valign="top">
        Browse in :
   </td>
   <td valign="top">

                                    <a href="http://www.vaporbase.com/postings/">All</a>

                 &gt;                     <a href="http://www.vaporbase.com/postings/c36/">subjects</a>

                 &gt;                     <a href="http://www.vaporbase.com/postings/c42/">rails</a>
<br />

                                    <a href="http://www.vaporbase.com/postings/">All</a>

                 &gt;                     <a href="http://www.vaporbase.com/postings/c36/">subjects</a>

                 &gt;                     <a href="http://www.vaporbase.com/postings/c43/">django</a>
<br />

                                    <a href="http://www.vaporbase.com/postings/c42-43/">Any of these categories</a>

                -                    <a href="http://www.vaporbase.com/postings/c42+43/">All of these categories</a>
<br />
</td>
</tr>
</table>






<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xd</em>
and <em>user-summary-[publicationtype].xd</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles
The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Rails and Django - Routing and Controllers (part 7/15)</h1>
<p><strong>Author:</strong>&nbsp;linoj</p>
<p>
<strong>Date:</strong> March 11, 2007 6:09:05 AM  or Sun, 11 March 2007 06:09:05 </p>
<p><strong>Summary:</strong>&nbsp;A technical manager's guide to evaluating web development frameworks, with a detailed review of Ruby on Rails and the Django (Python) projects. (Start here: <a href="rails-django">Whitepaper index</a>)</p>
<p><strong>Body:</strong>&nbsp;<h2>URL Routing</h2><p><em>URL routing</em> is how the framework interprets an incoming request from the user&#39;s browser, and decides which function to direct it to, passing along any additional parameters from the user. The router allows “friendly URLs”, that are human-readable and don&#39;t have &quot;those scary <em>?x=something</em> blah blah things&quot; in the strings (as someone I know put it)!</p><h3>Rails</h3><p>In Rails the config/routes.rb file defines the URL mappings. For example,<br /></p><pre>map.connect &#39;:controller/:action/:id&#39;<br /></pre><p>will route any URL in this format to the corresponding controller class, action method, and pass along the id as an argument. Thus, <em>http://www.mysite.com/products/detail/123</em> goes to the <em>ProductsController</em>, <em>“detail”</em> action, for <em>id = 123</em>.</p><p>But you can change the mapping with new rules as needed, perhaps even change the url layout of the site without out changing  any of the link_to, layout, form tags, etc in the code or templates.</p><p>Rails provide a URL generator (url_for method) so you do not need to hardcode real URLs in your code or templates. It uses the rules defined in routes.rb, so that logic is maintained in a single central location.</p><h3>Django</h3><p>In Django, the <em>urls.py</em> file defines the URL mappings. It uses standard regular expression (regex) syntax to parse the URL string and map it to your functions. For example, <br /></p><pre>(r&#39;^(?P&lt;object_id&gt;\d+)/products/detail/$&#39;, &#39;store.products.view&#39;),<br /></pre><p>will route any URL in format <a href="http://www.mysite.com/products/detail/NNN" target="_blank">www.mysite.com/products/detail/NNN</a> to the app “store”, view “products”, method “detail”, with argument id = NNN. </p><p>Note, you explicitly state the mapping from the URL strings to the corresponding class and method. The URL is completely decoupled from the structure of your app.  Thus, for example, you could rename your app or classes without affecting the URLs the rest of the world uses to access your site. And you can provide multiple routes to the same functions, for example to support legacy URLs on a new site.</p><p>Django recently added a template tag to generate URLs based on the urls.py configuration.   </p><p>Django uses an HttpRequest and HttpResponse objects to pass state through the system. HttpRequest contains metadata about the request (e.g post and session info). Each view is responsible for return an HttpResponse object (e.g includes the HTML body etc).</p><h3>Opinion</h3><p>Django&#39;s loosely coupled URL mapping and regex syntax is much more flexible and thus more powerful.</p><p>Unfortunately I was born missing the &quot;regex gene&quot;! For years I have tried to learn it, and failed pathetically. Sure, I can copy and make small changes from examples. But I do hesitate to put a key feature of my websites into my regex-challenged hands.  </p><p>With regard to loose coupling in Rails, there is a workaround, by creating a dummy controller class which then makes the call to the actual one. Its really a kludge, but it I suppose it works.</p><p><em>Conclusion: Django&#39;s loosely coupled, regex based URL mapping wins against Rails&#39; declarative mapping, 4 to 3.</em></p><p>&nbsp;</p><table border="1"><tbody><tr><td><strong>URL Routing  </strong></td><td><strong>Rails  </strong></td><td><strong>Django  </strong></td></tr><tr><td>URL Mapping </td><td><p>centralized, declarative  </p><p>(routes.rb) </p></td><td><p>distributed, regex </p><p>(urls.py) </p></td></tr><tr><td>Reverse Mapping </td><td>complete </td><td>limited </td></tr><tr><td><strong>MY RATING: (1=worst, 5=best)  </strong></td><td><strong>3</strong><br /></td><td><strong>4 </strong></td></tr></tbody></table><p>&nbsp;</p><h2>Controllers / Views</h2><p>The controllers are the real meat of your application. Controllers define the action methods that handle specific requests from users. In Rails this is the Controller class; in Django its called Views. (And what Rails calls Views are equivalent to what Django calls <em>templates</em>).  </p><p>Surprisingly, I don&#39;t have a lot to say here about controllers. Or else I&#39;d have too much. That&#39;s because when you get into the controllers, you&#39;re really describing the programming language and framework&#39;s API, libraries and helper functions.  </p><p>In both Rails and Django, the controller actions are usually pretty short, just a few lines of code. They grab some data via the Model class, perhaps do some processing, and package variables that are passed into the templates. They might also handle error conditions and exceptions (for example, in a shopping application, if the URL requests a product Id that doesn&#39;t exist in the database). </p><p>Rails <em>scaffolding</em> provides a quick and dirty automatic generation of the Controllers and Views for a model. These are intended as temporary placeholders while you incrementally build your app.</p><p>Django comes with built-in generic views. Not the same as Rail&#39;s scaffolding, these are handy for common actions such as list/detail interfaces, archive pages, and a set of view for creating, editing, and deleting objects. Of course, you still provide individual templates for any custom views. </p><p>In Django, you can augment views with “decorators”, a Python shortcut construct for specifying meta-attributes and contstraints. For example, a view method preceeded with @login_required will use the integrated authentication system to verify the user is logged in or he&#39;ll be redirected to a login page. In Rails you can accomplish the same thing with &quot;filters&quot;.  </p><p><em>Conclusion: I rate both a 3, and any real differences are covered in the other criteria.</em></p><p>&nbsp;</p><table border="1"><tbody><tr><td><strong>Controllers / Views  </strong></td><td><strong>Rails  </strong></td><td><strong>Django  </strong></td></tr><tr><td><strong>MY RATING: (1=worst, 5=best)  </strong></td><td><strong>3</strong><br /></td><td><strong>3 </strong><br /></td></tr></tbody></table><p>&nbsp;</p><p>&nbsp;</p></p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
        <p>Last modified on Mar 22, 2007 1:12:06 AM by <a href="http://www.vaporbase.com/roles/3">linoj</a></p>
        <p>



<div>
   <p class="xar-cm-note xar-sub">
 Note: Comments are owned by the poster. We are not responsible for their content. </p>
</div>
    <div class="xar-accent-outline xar-cm-comment">
    <div>
         <a name="51"></a>
                <form action="http://www.vaporbase.com/?module=comments&amp;func=reply" method="post" class="xar-cm-actions">
                    <div>
                        <input type="hidden" name="header[modid]" value="151" />
                        <input type="hidden" name="header[itemtype]" value="9" />
                        <input type="hidden" name="header[objectid]" value="97" />
                        <input type="hidden" name="header[pid]" value="51" />
                        <input type="hidden" name="receipt[returnurl][decoded]" value="http://www.vaporbase.com/postings/Rails_and_Django_-_Routing_and_Controllers_%28part_7/15%29?&amp;depth=1&amp;order=1&amp;sortby=2&amp;render=flat" />
                        <input type="hidden" name="receipt[returnurl][encoded]" value="http%3A%2F%2Fwww.vaporbase.com%2Fpostings%2FRails_and_Django_-_Routing_and_Controllers_%2528part_7%2F15%2529%3F%26amp%3Bdepth%3D1%26amp%3Border%3D1%26amp%3Bsortby%3D2%26amp%3Brender%3Dflat" />
                        <input type="hidden" name="receipt[action]" value="reply" /> 
                        <input type="submit" name="submit" id="submit-reply51" value="Reply" />
                   </div>
               </form>

                <h4>Rails and Django - Routing and Controllers (part 7/15)</h4>
<!-- show changelog -->
<!-- end changelog -->
           <span class="xar-sub">
 Posted by:                     Anonymous on                 March 18, 2007 08:56 PM</span>
       </div>
       <div class="xar-accent xar-cm-comment">
                Rails routes have regular expressions allowed. It is discussed right on the first page of the Routing manual - scroll down to &quot;Example 2.&quot; Sure, they don't explicitly use the term &quot;regular expressions,&quot; but any programmer would recognize the perl-compatible regex immediately.

Second, Rails controllers sure as heck are &quot;decoupled&quot; from route URLs under your definition. Your one example may not be, but the following route,

map.connect 'product/:id', :controller =&gt; &quot;system&quot;, :action =&gt; &quot;fetch&quot;

sends all requests to 'product/x' to the System controller and calls the &quot;fetch&quot; action.

This entire evaluation seems to be very, very poorly researched.                <p>
                    <a href="http://www.vaporbase.com/?module=comments&amp;func=display&amp;cid=51" title="Permalink" rel="bookmark">
                       #
                   </a>
               </p>

       </div>

</div>

    <div class="xar-accent-outline xar-cm-comment">
    <div>
         <a name="52"></a>
                <form action="http://www.vaporbase.com/?module=comments&amp;func=reply" method="post" class="xar-cm-actions">
                    <div>
                        <input type="hidden" name="header[modid]" value="151" />
                        <input type="hidden" name="header[itemtype]" value="9" />
                        <input type="hidden" name="header[objectid]" value="97" />
                        <input type="hidden" name="header[pid]" value="52" />
                        <input type="hidden" name="receipt[returnurl][decoded]" value="http://www.vaporbase.com/postings/Rails_and_Django_-_Routing_and_Controllers_%28part_7/15%29?&amp;depth=1&amp;order=1&amp;sortby=2&amp;render=flat" />
                        <input type="hidden" name="receipt[returnurl][encoded]" value="http%3A%2F%2Fwww.vaporbase.com%2Fpostings%2FRails_and_Django_-_Routing_and_Controllers_%2528part_7%2F15%2529%3F%26amp%3Bdepth%3D1%26amp%3Border%3D1%26amp%3Bsortby%3D2%26amp%3Brender%3Dflat" />
                        <input type="hidden" name="receipt[action]" value="reply" /> 
                        <input type="submit" name="submit" id="submit-reply52" value="Reply" />
                   </div>
               </form>

                <h4>Rails and Django - Routing and Controllers (part 7/15)</h4>
<!-- show changelog -->
<!-- end changelog -->
           <span class="xar-sub">
 Posted by:                     linoj on                 March 19, 2007 11:29 AM</span>
       </div>
       <div class="xar-accent xar-cm-comment">
                Hox: you're right, I misunderstood Rails routes. I believe the doc you refer to is here ( <a href="http://manuals.rubyonrails.com/read/chapter/65" target="_blank">http://manuals.rubyonrails.com/read/chapter/65</a> ) I plan to redraft that section.                 <p>
                    <a href="http://www.vaporbase.com/?module=comments&amp;func=display&amp;cid=52" title="Permalink" rel="bookmark">
                       #
                   </a>
               </p>

       </div>

</div>

    <div class="xar-accent-outline xar-cm-comment">
    <div>
         <a name="550"></a>
                <form action="http://www.vaporbase.com/?module=comments&amp;func=reply" method="post" class="xar-cm-actions">
                    <div>
                        <input type="hidden" name="header[modid]" value="151" />
                        <input type="hidden" name="header[itemtype]" value="9" />
                        <input type="hidden" name="header[objectid]" value="97" />
                        <input type="hidden" name="header[pid]" value="550" />
                        <input type="hidden" name="receipt[returnurl][decoded]" value="http://www.vaporbase.com/postings/Rails_and_Django_-_Routing_and_Controllers_%28part_7/15%29?&amp;depth=1&amp;order=1&amp;sortby=2&amp;render=flat" />
                        <input type="hidden" name="receipt[returnurl][encoded]" value="http%3A%2F%2Fwww.vaporbase.com%2Fpostings%2FRails_and_Django_-_Routing_and_Controllers_%2528part_7%2F15%2529%3F%26amp%3Bdepth%3D1%26amp%3Border%3D1%26amp%3Bsortby%3D2%26amp%3Brender%3Dflat" />
                        <input type="hidden" name="receipt[action]" value="reply" /> 
                        <input type="submit" name="submit" id="submit-reply550" value="Reply" />
                   </div>
               </form>

                <h4>Rails and Django - Routing and Controllers (part 7/15)</h4>
<!-- show changelog -->
<!-- end changelog -->
           <span class="xar-sub">
 Posted by:                     Anonymous on                 March 05, 2009 04:24 PM</span>
       </div>
       <div class="xar-accent xar-cm-comment">
                &gt;&gt;This entire evaluation seems to be very, very poorly researched. 
<br/>
Oh give me a break.  It's good enough for a nice overview, and very appreciated.                <p>
                    <a href="http://www.vaporbase.com/?module=comments&amp;func=display&amp;cid=550" title="Permalink" rel="bookmark">
                       #
                   </a>
               </p>

       </div>

</div>

<script type="text/javascript" src="modules/base/xartemplates/includes/submitonce.js"></script>
  <h3>Post a new comment</h3> 
  <form action="http://www.vaporbase.com/?module=comments&amp;func=reply" method="post" name="post" id="post" onSubmit="submitonce(this)" id="post"
 >
   <div class="xar-ib-wrapper xar-accent-outline">
<div class="xar-ib-actionpanel xar-accent">
         <span>
 BBCode Actions             : 
          </span>
          <span>
            <!-- New xaraya style link tag <xar:set name="$stylesheet">xarTplAddStyleLink('bbcode', 'bbcode')</xar:set> -->

<span>
    <input type="button" accesskey="z" name="addbbcode18" value=" p " onclick="bbstyle(18)" onmouseover="document.post.helpbox.value='Paragraph: [p]text[/p] (alt+z)'; return true" />
    <input type="button" accesskey="b" name="addbbcode0" value=" b " style="font-weight:bold;" onclick="bbstyle(0)" onmouseover="document.post.helpbox.value='Bold text: [b]text[/b] (alt+b)'; return true" />
    <input type="button" accesskey="i" name="addbbcode2" value=" i " style="font-style:italic;" onclick="bbstyle(2)" onmouseover="document.post.helpbox.value='Italic text: [i]text[/i] (alt+i)'; return true" />
    <input type="button" accesskey="u" name="addbbcode4" value=" u " style="font-style: underline;" onclick="bbstyle(4)" onmouseover="document.post.helpbox.value='Underline text: [u]text[/u] (alt+u)'; return true" />
    <input type="button" accesskey="q" name="addbbcode6" value="Quote" onclick="bbstyle(6)" onmouseover="document.post.helpbox.value='Quote text: [quote]text[/quote] (alt+q)'; return true" />
    <input type="button" accesskey="c" name="addbbcode8" value="Code" onclick="bbstyle(8)" onmouseover="document.post.helpbox.value='Code display: [code=xml]code[/code] (alt+c)'; return true" />
    <input type="button" accesskey="p" name="addbbcode14" value="Img" onclick="bbstyle(14)" onmouseover="document.post.helpbox.value='Insert image: [img]http://image_url[/img] (alt+p)'; return true" />
    <input type="button" accesskey="w" name="addbbcode16" value="URL" style="text-decoration: underline;" onclick="bbstyle(16)" onmouseover="document.post.helpbox.value='Insert URL: [url]http://url[/url] or [url=http://url]URL text[/url] (alt+w)'; return true" />
</span>
<label for="addbbcode20">
 Font color     :
</label>
<select name="addbbcode20" onchange="bbfontstyle('[color=' + this.form.addbbcode20.options[this.form.addbbcode20.selectedIndex].value + ']', '[/color]');this.selectedIndex=0;" onmouseover="document.post.helpbox.value='Font color: [color=red]text[/color] Tip: you can also use color=#FF0000'; return true">
   <option style="color:black; background-color: #FAFAFA" value="#444444" class="xar-bbcode-genmed">
 Default </option>
   <option style="color:darkred; background-color: #FAFAFA" value="darkred" class="xar-bbcode-genmed">
 Dark Red </option>
   <option style="color:red; background-color: #FAFAFA" value="red" class="xar-bbcode-genmed">
 Red </option>
   <option style="color:orange; background-color: #FAFAFA" value="orange" class="xar-bbcode-genmed">
 Orange </option>
   <option style="color:brown; background-color: #FAFAFA" value="brown" class="xar-bbcode-genmed">
 Brown </option>
   <option style="color:yellow; background-color: #FAFAFA" value="yellow" class="xar-bbcode-genmed">
 Yellow </option>
   <option style="color:green; background-color: #FAFAFA" value="green" class="xar-bbcode-genmed">
 Green </option>
   <option style="color:olive; background-color: #FAFAFA" value="olive" class="xar-bbcode-genmed">
 Olive </option>
   <option style="color:cyan; background-color: #FAFAFA" value="cyan" class="xar-bbcode-genmed">
 Cyan </option>
   <option style="color:blue; background-color: #FAFAFA" value="blue" class="xar-bbcode-genmed">
 Blue </option>
   <option style="color:darkblue; background-color: #FAFAFA" value="darkblue" class="xar-bbcode-genmed">
 Dark Blue </option>
   <option style="color:indigo; background-color: #FAFAFA" value="indigo" class="xar-bbcode-genmed">
 Indigo </option>
   <option style="color:violet; background-color: #FAFAFA" value="violet" class="xar-bbcode-genmed">
 Violet </option>
   <option style="color:white; background-color: #FAFAFA" value="white" class="xar-bbcode-genmed">
 White </option>
   <option style="color:black; background-color: #FAFAFA" value="black" class="xar-bbcode-genmed">
 Black </option>
</select>
<label for="addbbcode22">
 Font size     :
</label>
<select name="addbbcode22" onchange="bbfontstyle('[size=' + this.form.addbbcode22.options[this.form.addbbcode22.selectedIndex].value + ']', '[/size]')" onmouseover="document.post.helpbox.value='Font size: [size=x-small]small text[/size]'; return true">
   <option value="7" class="xar-bbcode-genmed">
 Tiny </option>
   <option value="9" class="xar-bbcode-genmed">
 Small </option>
   <option value="12" selected="selected" class="xar-bbcode-genmed">
 Normal </option>
   <option value="18" class="xar-bbcode-genmed">
 Large </option>
   <option value="24" class="xar-bbcode-genmed">
 Huge     </option>
</select>
<a href="javascript:bbstyle(-1)" class="xar-bbcode-genmed" onmouseover="document.post.helpbox.value='Close all open bbCode tags'; return true">Close Tags</a>
<span class="gensmall">
    <input type="text" name="helpbox" size="50" maxlength="100" class="helpline" value="Tip: Styles can be applied quickly to selected text." />
</span>         </span>
       </div>
       <div class="xar-ib-leftpanelshort">
         <p>
 Name :
              Anonymous</p>
         <label for="package-title">
 Title: </label>
            <input class="xar-ib-field" type="text" name="package[title]" id="package-title" value="Rails and Django - Routing and Controllers (part 7/15)" tabindex="1" />
         <label for="package-text">
 Comment: </label>
<textarea class="xar-ib-fieldtext" name="package[text]" id="package-text" tabindex="2"></textarea>

          <input type="hidden" name="header[modid]" id="header-modid" value="151" /> 
          <input type="hidden" name="header[objectid]" id="header-objectid" value="97" /> 
          <input type="hidden" name="header[itemtype]" id="header-itemtype" value="9" />
<input type="hidden" name="header[pid]" id="header-pid" value="0" />
          <input type="hidden" name="receipt[returnurl][decoded]" id="receipt-returnurl-decoded" value="http://www.vaporbase.com/postings/Rails_and_Django_-_Routing_and_Controllers_%28part_7/15%29?&amp;depth=1&amp;order=1&amp;sortby=2&amp;render=flat" />
          <!--<input type="hidden" name="receipt[returnurl][encoded]" id="receipt-returnurl-encoded" value="#$receipt['returnurl']['encoded']#" />-->
          <input type="hidden" name="receipt[action]" id="receipt-action" /> 
          <input type="submit" id="receipt-action-preview" onclick="document.getElementById('receipt-action').value='preview'" value="Preview" /> 
          <input type="submit" id="receipt-action-submit" onclick="document.getElementById('receipt-action').value='submit'" value="Submit" />
       </div>
</div>
 </form>
</p>
        <p></p>
        <p></p>
</div>
   </channel>
</rss>
