Saturday, June 29, 2013

Change template block via AJAX

Hi,

I have an application containing a topbar and rest is content area.

In my 'base.html', I've defined two blocks -

<body>
  {% block topbar %}{% endblock topbar %}
  {% block page_content %}
        {% block sidebar %}
        {% endblock sidebar %}
                                  
        {% block main %}
        {% endblock main %}
    {% endblock page_content %}
</body>

These two blocks are then overridden by child templates.
The topbar contains a search input. The search query is sent via AJAX, and the results are loaded in respective child blocks through client-side templating.

Now, I want that whenever user enters a search query for a user via a radio button instead of default, The block 'page_content' should get overridden by another template 'user_results.html'. ( I'll know it client-side itself )
This can be done by redirecting to a path like '/search/user/', but that would involve reloading of the page.
Is this possible via an AJAX request, and then the server would load another template which will replace the 'page_content' block without page refresh ?

--
Regards,
Parin Porecha

say Kifflom! and look forward to 17.09.13 !

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment