0

I am following this answer to make smooth page switches: Rendering JSON objects using a Django template after an Ajax call

How do I make Django understand, that I'm on the other page already?

I want the list element to obtain 'active' class and to have /leaders/ in browser url path when I click on the link and load leaderboard template. Say i have:

leaderboard.html:

<li{% if path == leaders %} class="active"{% endif %}>  
   <a href="/leaders/">Leaderboard</a>
</li>

urls.py:

url(r'^leaders/$', 'index.views.leaderboard', name='leaders'),

view:

def leaderboard(request):
  ...
  if request.is_ajax():
    return_str = render_block_to_string('leaderboard.html', 'block_name', context)
    return HttpResponse(return_str)
  else:
    response = render_to_response('leaderboard.html', context)
    return response    

Edit: I've tried to use window.history.pushState, it changed url in browser, but did not tell anything to django.

Community
  • 1
  • 1

0 Answers0