Django-easy-pjax not working really

北城余情 提交于 2019-12-22 01:06:52

问题


I use from django-easy-pjax. I have this base code:

ubase.html

 <script type="text/javascript" src="{% static "/static/js/jquery-1.9.1.min.js" %}"></script>
<script src="{% static "/static/js/jquery.pjax.js" %}"></script>
{% block side%}
        It is {% now "c" %} 

sdfdsfdsf
<a href="/uu/">uu</a>
<a href="/uu1/">uu1</a>
<br/><br/><br/><br/><br/><br/>

{%endblock side%}


{%block main%}

sdfdfsdfdsfdsfdfdsf
{%endblock main%}

entry_index.html

{% extends "ubase.html"|pjax:request %}
{%block main%}
1
{%endblock main%}

entry_index2.html

{% extends "ubase.html"|pjax:request %}
{%block main%}
2
{%endblock main%}

my views:

def entry_index1( request ):
    return render_to_response('entry_index1.html', {}, context_instance = RequestContext(request))

def entry_index( request ):
    return render_to_response('entry_index.html', {}, context_instance = RequestContext(request))

and my url

url(r'^uu/$', search_views.entry_index),
url(r'^uu1/$', search_views.entry_index1),

but when I use click on uu link or uu1 link the time change and pjax not work really like this example.Why it is so?


回答1:


Make sure you have django.core.context_processors.request added to TEMPLATE_CONTEXT_PROCESSORS and pjax templates to answer for PJAX request, in your case pjax_ubase.html. Take a look at the source code of the template tag: https://github.com/nigma/django-easy-pjax/blob/master/easy_pjax/templatetags/pjax_tags.py




回答2:


Im sure you don't need this anymore. but you should have added this :D. This is not mentioned anywhere in the documentation

<script>
$(document).ready(function ($) {
    console.log("Hello im here ");
    "use strict";
    $(document).pjax("a", "#pjax-container", {timeout: 10000});

    $(document).on("pjax:beforeSend", function(e) {
    console.log("im before sending ");
             return true;

    });

    $(document).on("pjax:send", function(e) {
        $("#loading").removeClass("hidden")
    });

    $(document).on("pjax:complete", function() {
        $("#loading").addClass("hidden")
    });

});
</script>


来源:https://stackoverflow.com/questions/17075281/django-easy-pjax-not-working-really

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!