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 1021675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:20:43+00:00 2026-05-16T11:20:43+00:00

How do I refresh a certain element within a django template? Example: {% if

  • 0

How do I refresh a certain element within a django template?
Example:

{% if object.some_m2m_field.all %}
    <h3>The stuff I want to refresh is below</h3>
    <div id="the-div-that-should-be-refreshed">
    {% for other_object in object.some_m2m_field.all %}
        <a href="www.example.com">{{ other_object.title }}</a>
        &nbsp;
    {% endfor %}
    </div>
{% endif %}

Lets say some other element in the page triggers a javascript that should refresh the div above. Is there a way to cause django to refresh this specific element within the template?

If not, I’ll have to monkey-patch the div using regular JS or jQuery methods and not use the great power of django’s template layer. Also, the above code is a simplification of the actual template, I use much of the template’s power, so monkey-patching the resulting html will be a nightmare…

  • 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-05-16T11:20:44+00:00Added an answer on May 16, 2026 at 11:20 am

    You could use an async request to fill the div element.
    The async request is answered by Django using the template engine.

    In this case, you would have to outsource the template code of the div element into a separate template file.

    UPDATED WITH EXAMPLE:

    Javascript:
    For refreshing the view asynchronously, use JQuery for example:

    $.ajax({
      url: '{% url myview %}',
      success: function(data) {
      $('#the-div-that-should-be-refreshed').html(data);
      }
    });
    

    Async View:

    def myview(request):
        object = ...
        return render_to_response('my_template.html', { 'object': object })
    

    Template:

    {% for other_object in object.some_m2m_field.all %}
        <a href="www.example.com">{{ other_object.title }}</a>
        &nbsp;
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a button set up to refresh a certain div when it's clicked.
I have a UIView that updates based on data in a certain object. I'd
I'm trying to control the caching of files within a certain directory. I want
instead of a whole page refresh after a certain time, i'd just like a
Refresh an int64edit and get selected element. I have an int64edit, when I select
I m trying to refresh the screen on clicking a button so i want
I want to refresh a table using a SSIS package every time the user
In my web application (ASP.NET MVC), I need to do a certain function (refresh
I'm using a basic timer that calls this method: - (void) refresh:(id)obj { if
I've got a web page that allows to start a certain process and then

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.