Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use Django views and template tag simultanosly?
    text
    copied!<p>In my Django-template:</p> <pre><code>&lt;div class="A"&gt; {% url renders_data object.id %} &lt;/div&gt; &lt;div class="B"&gt; {% render_data object.id %} &lt;/div&gt; </code></pre> <p>Div <code>A</code> is common way to call a method in <code>views.py</code> whereas Div <code>B</code> is for template tags.</p> <p>User will open a link. Let's say: <code>/myapp/test/</code> a page will open contain two template tag section at the page. Name of this tag is <code>render_data</code> I want to load the data into each template tag with <code>Ajax</code>. To work with it we need <code>request.ajax:</code>. That is why i thought to write views method. I thought to complete it with the following way:</p> <p><li> I wrote the exact copy of <code>template tag</code> in <code>views.py</code> (renders_data with passing object_id parameter) and render it to the right template. When i open the <code>maypp/test</code> after removing the <code>div A</code> from template. It shows the <code>URL</code> (<code>myapp/test/&lt;object_id&gt;</code>) in each template tags section (each corner) except the data. Is their any possibility to show the context except this URL <a href="https://dl.dropbox.com/u/21766438/Screenshot%20at%202012-06-19%2001_34_22.png" rel="nofollow">See the image when i choose this option</a></li></p> <p><li> Second i also thought to import views method (<code>renders_data</code>) in template tag (<code>render_data</code>). So that data will display in each corner and <code>request.Ajax:</code> will also work. if this can be possible then how? </li></p> <p>I am not able to solve this issue. please help me :(</p> <p>See how the render_data looks like:</p> <pre><code> @register.simple_tag def render_widget(object_id): from myapp.plugins.model import Widgetsetting widget_setting = Widetsetting.objects.get(id = object_id) widget = widget_settings.get_widget() template_name = widget.template_name context = widget.context(widget=widget_settings) t = get_template("widgets/%s" % template_name) return t.render(Context(context)) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload