Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would recommend just plodding through the <a href="https://docs.djangoproject.com/en/dev/intro/tutorial01/">official tutorial</a> and I think realization will dawn and enlightenment will come automatically.</p> <p>Basically: When you issue a request: '''http://mydomain/myblog/foo/bar''' Django will:</p> <ol> <li>resolve <code>myblog/foo/bar</code> to a function/method call through the patterns defined in urls.py</li> <li>call that function with the request as parameter, e.g. <code>myblog.views.foo_bar_index(request)</code>.</li> <li>and just send whatever string that function returns to the browser. Usually that's your generated html code.</li> </ol> <p>The view function usually does the following:</p> <ol> <li>Fill the context dict for the view</li> <li>Renders the template using that context</li> <li>returns the resulting string</li> </ol> <p>The template generic view allows you to skip writing that function, and just pass in the context dictionary.</p> <p>Quoting the django docs:</p> <pre><code>from django.views.generic import TemplateView class AboutView(TemplateView): template_name = "about.html" </code></pre> <p>All views.generic.*View classes have views.generic.View as their base. In the <a href="https://docs.djangoproject.com/en/dev/ref/class-based-views/#django.views.generic.base.View">docs</a> to that you find the information you require. Basically:</p> <pre><code># urls.py urlpatterns = patterns('', (r'^view/$', MyView.as_view(size=42)), ) </code></pre> <p>MyView.as_view will generate a callable that calls views.generic.View.dispatch() which in turn will call MyView.get(), MyView.post(), MyView.update() etc. which you can override.</p> <p>To quote the docs:</p> <blockquote> <p>class View</p> <p>dispatch(request, *args, **kwargs)</p> <p>The view part of the view -- the method that accepts a request argument plus arguments, and returns a HTTP response. The default implementation will inspect the HTTP method and attempt to delegate to a method that matches the HTTP method; a GET will be delegated to get(), a POST to post(), and so on.</p> <p>The default implementation also sets request, args and kwargs as instance variables, so any method on the view can know the full details of the request that was made to invoke the view.</p> </blockquote> <p>The big plusses of the class based views (in my opinion):</p> <ol> <li>Inheritance makes them <strong>dry</strong>.</li> <li>More declarative form of programming</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload