Thursday, October 13, 2011

Re: Please help to get templates working at all

On Thursday, 13 October 2011 16:36:21 UTC+1, Piotr Hosowicz wrote:
I am writing my personal contact book and now want to make wish list
for Christmas. I cannot get simplest template working, the template
is:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Kampanie</title>
</head>
<body>

{% for campaign in campaigns %}
{{ campaign.name }}
{% endfor %}

</body>
</html>

The model is :

class Campaign(models.Model):
    name = models.CharField(u"Nazwa", max_length=255, null=False,
blank=False)
    objects = CampaignManager()
    def __unicode__(self):
        return "%s" % unicode(self.name)

and the view is:

def campaigns(request):
    form = CampaignForm(request.GET)
    ctx = {'form': form, "action": "view"}
    return render_to_response("campaigns.html", ctx,
context_instance=RequestContext(request))

The code is greatly copy and paste from working parts. I'd be very
grateful for help, I amd dying of bore and am keen to code, but
unfortunately my Python friend that usually helped me is too busy
nowadays.

And Merry Christmas to all :-)

Regards,

Piotr Hosowicz


Your view doesn't seem to have anything at all to do with your template. The only thing you pass to the template context is a form, which isn't mentioned at all in the template, and you don't pass the only variable which is used on the template, which is "campaigns".

Are you sure you've posted the correct view? I would expect something like this:

    def campaigns(request):
        ctx = {'campaigns': Campaign.objects.all()}
        return render_to_response("campaigns.html", ctx, 
context_instance=RequestContext(request)) 

--
DR.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/fH3oAzeJNNIJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment