Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass a "request" parameter at the time of calling a method in template tags in django
    primarykey
    data
    text
    <p>I am stuck in a very weird situation. There is a two method defined in templatetag/somefile.py with named : <b>ajax_print_widget</b> and <b>render_widget</b></p> <pre><code> def ajax_print_widget(request, template, context1 ): if request.is_ajax(): q = request.GET.get( 'q' ) if q is not None: data = { 'results': context1, } import pdb; pdb.set_trace() return render_to_response( template, data, context_instance = RequestContext( request ) ) @register.simple_tag def render_widget(widget_settings): widget = widget_settings.get_widget() template_name = widget.template_name context = widget.context(widget=widget_settings) t = get_template("widgets/%s" % template_name) return ajax_print_widget(t,context) </code></pre> <p>My main motive is to pass the data using Ajax (as i am checking in ajax_print_widget method) and render it to a template and rest of the things will be handled by jquery in a given template name. To perform this things i am performing the followings steps:</p> <ul>1. In render_widget method i am getting two variable which i need for Ajax purpose i.e. template name ('t') and the required data ('context') </ul> <ul>2. Now i need to pass these two variable as a parameter to ajax_print_widget method by calling it at the time of returning from render_widget (see the code)</ul> <ul>3. As you see that i need an extra parameter i.e. 'request' in ajax_...method (required for checking `request.is.ajax():`). But i am not able to find out any way to send this parameter to ajax..method </ul> <p>I tried this by writing :</p> <pre><code>return ajax_print_widget(request, t, context) </code></pre> <p>but it is showing an error i.e. request is not a global variable (that is obvious) and if i leave rest of the code as i pasted it above then it shows another error i.e. ajax_print takes 3 arguments and 2 are given (right) Now i am not getting any hint to solve this issue and without passing request it can't work for me.</p> <p>Apart from that i have an doubt about template tag. I even search this render_widget method and i didn't found at any file where from it got called. Would you also please tell me the significance of template tags. The methods are defined in template tag are called from somewhere or why we write this in template tag?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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