Home Django: Include template with variables rendered from views.py into another template
Reply: 0

Django: Include template with variables rendered from views.py into another template

user1045
1#
user1045 Published in May 25, 2018, 8:57 am

I have a template plot.html inside app plot:

<div>
{{ plot|safe }}
</div>
some other divs here

The plot variable is calculated from views.py inside app plot:

class RenderView(TemplateView):
    def __init__(self):
        self.template_name = "plot.html"

    def get_context_data(self, **kwargs):
        context = super(RenderView, self).get_context_data(**kwargs)
        context['plot'] = PlotView().make_plot()
        return context

Now I want to include this template with the generated plot and other divs into another template from another app, another.html:

{% include "plot.html" %}

of course this does not generate the plot and other info from the views.py file.

I've been reading about template tags (https://docs.djangoproject.com/en/2.0/howto/custom-template-tags/), but I'm unsure what goes into poll_extras.py there or if tags is the right solution.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.384618 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO