James Bennett wrote:
On 12/30/05, Michael Hipp <[EMAIL PROTECTED]> wrote:

I have a base.html that is a skeleton html document with this call to my
'simple' app added:

  {{ simple.saysomething }}


You never call the view function from inside the template; by the time
Django is rendering the template, the view code has already been
executed. What happens, roughly, is this:

1. A request comes in, and Django looks at the URLConf to see if it
matches any pattern there.
2. If it does, Django calls the view listed in the URLConf for that pattern.
3. The view code does whatever processing it needs, then generates a
context -- a dictionary of keys and values -- which it passes to a
template for rendering. The view code is responsible for determining
which template will be loaded and used.
4. The template renders using the values passed in the context.

So the template tag '{{ simple.saysomething }}' would expect the view
to have included in the context a key/value pair where 'simple' is the
value, and the key is an object with a 'saysomething' attribute.

Probably a better way of doing this would be:

def saysomething(request, message):
    return render_to_response('base', {'message': message})

This takes in whatever value you want to pass as the message, and then
hands it off to the template 'base.html' as the variable 'message'.
And then in the template, just have '{{ message }}', which will render
the text.

I'm not sure I grasped the above. And it's possible I'm asking the question in the wrong way. So allow me to try again...

I'm trying to construct the simplest possible case of a single-page website with a single ultra-simple Django app inside that outputs something to the screen when viewed.

Per Adrian's earlier suggestion, I'm still using
  (r'.*', 'django.views.generic.simple.direct_to_template',
    {'template': 'base'})
as my urlpattern.

Where I seem to be confused is that all the urlpattern examples in the docs all seem to be geared toward the "mysite.com/foo" where you give it a pattern to catch /foo and then specify a view like 'mysite.apps.foo.views.fooview'. But what about the "root" of the website, how do you specify a view for just "mysite.com"?

In other words, I have no unique url pattern to trap to send it to a view for my simple.saysomething app.

Did that make any sense at all? I'm feeling really dense right about now. Hopefully it is a temporary condition. :-)

Also, what is the best way to get debug output from Django? I tried a 'print'
statement in 'saysomething' but it seemed to go nowhere.


If you need to debug and see what output is actually getting to your
template, a simple way is to include, inside an HTML comment, a list
of any objects/variables you want to have access to in the template
and print out their names and values. For example, to test the above,
you might put this in your template:

<!-- Testing that the variable got passed correctly: variable
'message' has value {{ message }} -->

Thanks. What about the case where I need to get debugging output from deep in a routine and no obvious (to me, at least) way to bubble it up into the web browser?

I'm grateful for your help.

Michael

Reply via email to