Please help to get templates working at all

6 views
Skip to first unread message

Piotr Hosowicz

unread,
Oct 13, 2011, 11:36:21 AM10/13/11
to Django users
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

Daniel Roseman

unread,
Oct 13, 2011, 11:52:25 AM10/13/11
to django...@googlegroups.com
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.

Piotr Hosowicz

unread,
Oct 13, 2011, 12:00:06 PM10/13/11
to Django users


> 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".

Yeah, you are great, now I see what I wanted.

> 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))

This is exactly what I missed.

Thanks a lot and merry Christmas.

Piotr Hosowicz

Piotr Hosowicz

unread,
Oct 13, 2011, 12:08:21 PM10/13/11
to Django users


> 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".

Yeah, you are great, now I see what I wanted.

> 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))

Reply all
Reply to author
Forward
0 new messages