Re: How to set block variable in view code?

28 views
Skip to first unread message

Lachlan Musicman

unread,
Aug 18, 2014, 7:00:09 AM8/18/14
to django...@googlegroups.com
Daniel,

The template in the View is the end page you want created for eg testview.html.

testview.html:
{% extends "base.html" %}
{% block content %}TEST VIEW WITH OBJECT{% endblock %}


base.html:
<body>
<h2>
{% block side_hdr %}here is the side menu for all pages{% endblock%}
</h2>
<p>{% block content %}Base{% endblock %}</p>
</body>

The end product looks like:

<body>
<h2>here is the side menu for all pages</h2>

<p>TEST VIEW WITH OBJECT</p>

</body>

Does that make sense? So the testview.html extends the base.
Everything in teh base appears in teh testview, and testview wil
override anything from base.

cheers
L.


On 18 August 2014 20:45, Daniel Grace <danw...@gmail.com> wrote:
> I am struggling to understand block variables. I have two block variables
> in my HTML template as follows:
>
> <h2>
> {% block side_hdr %}{% endblock%}
> </h2>
> {% block content %}{% endblock %}
>
> How (if possible) do I set these variables in my class based view?
>
> class TestView(TemplateView):
> template_name = "base.html"
>
> Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/43795e2f-1f53-4df7-ba5f-79477ccd2f08%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
You have to be really clever to come up with a genuinely dangerous
thought. I am disheartened that people can be clever enough to do that
and not clever enough to do the obvious thing and KEEP THEIR IDIOT
MOUTHS SHUT about it, because it is much more important to sound
intelligent when talking to your friends.
This post was STUPID.
-----------------------------------------------------------------------------------------------------------
The Most Terrifying Thought Experiment of All Time
http://www.slate.com/articles/technology/bitwise/2014/07/roko_s_basilisk_the_most_terrifying_thought_experiment_of_all_time.html

Daniel Grace

unread,
Sep 14, 2014, 1:54:08 PM9/14/14
to django...@googlegroups.com
Thanks for the info.  I am beginning to see the power of these substitutions.
Reply all
Reply to author
Forward
0 new messages