2013-06-12 76 views
1

我使用django-easy-pjax。 我有这样的基本代码:Django-easy-pjax不能正常工作

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%} 

我的看法:

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

和我的网址

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

但是当我使用点击UU链接或UU1链接的时间变化,pjax不是真的像这样工作example。为什么会这样?

+0

u能请编辑在这里你了,使得它的工作,并添加代码'pjax_ubase.html'或u对代码进行任何其他更改,使其工作有什么变化! –

回答

3

确保您已django.core.context_processors.request加入TEMPLATE_CONTEXT_PROCESSORS和pjax模板来回答PJAX要求,你的情况pjax_ubase.html。看看模板标签的源代码:https://github.com/nigma/django-easy-pjax/blob/master/easy_pjax/templatetags/pjax_tags.py

+0

我正在做问题中所描述的完全相似。我已经添加了'django.core.context_processors.request'。我应该在'pjax_base.html'中写什么?它仍然没有工作。我对pjax很陌生,我对'jquery-pjax'感到困惑,即** django-easy-pjax app是一个帮助你将jquery-pjax与你的Django 1.5 **集成在一起的助手。因此,在使用'easy-pjax'时,我还必须配置服务器端的东西?我试了几个小时,请帮助我:(请留言,如果我怀疑疑问不清楚 –

+1

@AshishGupta很抱歉,对于迟到的回复。我忘记了我对django-easy-pjax知道的一切,哈哈,原因是因为有很多的SPA引擎优于这种黑客方式,而 –

+0

它好吧:),它更好地忘记这一点,并选择一个更好的选择:P即使我离开它,并选择django休息和angularjs :) –

1

我确定你不需要这个了。但你应该添加这个:D。这不是在文档中的任何地方提到

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