Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7978113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:24:10+00:00 2026-06-04T09:24:10+00:00

I am stuck in a very weird situation. There is a two method defined

  • 0

I am stuck in a very weird situation. There is a two method defined in templatetag/somefile.py with named : ajax_print_widget and render_widget

 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)

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:

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

I tried this by writing :

return ajax_print_widget(request, t, context)

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.

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:24:12+00:00Added an answer on June 4, 2026 at 9:24 am

    If you enable django.core.context_processors.request in your TEMPLATE_CONTEXT_PROCESSORS setting (it’s not in there by default) and change your tag to takes_context=True then you can get the request inside your template tag. https://docs.djangoproject.com/en/1.3/howto/custom-template-tags/#simple-tags

    @register.simple_tag(takes_context=True)
    def render_widget(context, widget_settings):
        request = context.get('request')
        # Rest of the tag goes here
    

    Note that this also requires your template to be rendered with a RequestContext.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are some very useful classes for working with images. I am stuck with
I am stuck in a weird Design problem, I am working on a two
I am stuck at a very weird problem. I mean I do not how
I'm stuck in this very easy problem (I hope it is for you). I
I am creating a very simple project on OpenGL and I'm stuck with rotations.
I don't know very much about css, but i'm a tid bit stuck. I
Hello there Stack Overflow, I hope you'll help me with my very first question
I'm getting very stuck on something that should be very easy. I am trying
It is very weird, and I don't have any idea what is the issue!
I have a very weird problem using OpenMP in my C++ code: void update(double

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.