> Yes. But I still seem to be off somewhere...
>
>  From 
> http://www.djangoproject.com/documentation/tutorial3/#write-your-first-view
> there is:
> --------------
> from django.utils.httpwrappers import HttpResponse
>
> def index(request):
>      return HttpResponse("Hello, world. You're at the poll index.")

HttpResponse just return the message to the caller, not directly to the screen.

>
> This is the simplest view possible. Go to "/polls/" in your browser, and you
> should see your text.
> --------------
>
> I don't know how to reconcile this with what James Bennett and limodou wrote
> about using render_to_response() instead of HttpResponse() as none of the
> examples in the docs use render_to_response() as their return value from the
> view method. So the advice seems contradictory to the docs.

render_to_response is a utility function provided by django, if you
don't want to use it, you can do it yourself, just like:

from django.utils.httpwrappers import HttpResponse
from django.core.template import loader, Context

def output(request, filename):
    response = HttpResponse()
    t = loader.get_template('base')
    c = Context({
        'message': 'message here',
    })
    response.write(t.render(c))
    return response
>
> The tutorial seems to be saying that anything returned from a view by way of
> the HttpResponse() call will be sent directly to the screen. And at another
> place is shows the url pattern to trap the correct url:
>    (r'^polls/$', 'myproject.apps.polls.views.index')
> Which seems a simple process of
>    urlpattern -> view -> template -> screen
>
Wrong, should be:

urldispatch -> view -> screen
                       |
                       v
                  template

template can only be called, but it cann't directly output to screen,
only views can.

> But I can't see in the tutorial example what is put in the template that will
> receive this "Hello, world..." output.
>
template receives variable, and it should be invoked by views.

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

Reply via email to