Hi Mario,

> I am new in Django. I am implementing a web application using the
> django template support. In this way, i am using a single 2-columns
> template. While the second column changes according to the presented
> content, the first column shows the menu and some statistical
> information for all pages. This information must indicate the number
> of entities of the model, for example the number of registered users.
>
> I want to know how show the number of registered users in that page.
> Do I need to retrieve this value to each action described in views.py?
> The code presented below does not work.
>
> <h2>Statistics</h2>
> <ul>
> <li>Users({{User.objects.count}})</li>
> ...
> </ul>

For these problems exists Template Variables.
You've got your view:
        
        From django.shortcuts import render_to_response
        def myView():
                #how many Users has my page?
                userCount = len(User.objects.all())
                #give the template vars to the template and return the
rendered html
                return render_to_response('my_template.html', {'user_count'
: userCount})


And this is your template:

<html><head><title>Hi</title></head><body>
        <table>
                <tr>
                        <td><span style="font-weight:
bold;">UserCount:</span> {{userCount}}</td>
                        <td><p>Hi</p>
                </tr>
</body></html>

Regards, Yanick

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to