【问题标题】:Django-easy-pjax not working reallyDjango-easy-pjax 没有真正工作
【发布时间】:2013-06-12 21:01:48
【问题描述】:

我使用来自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. 为什么会这样?

【问题讨论】:

  • 您能否在此处编辑您为使其正常工作所做的更改并添加pjax_ubase.html 的代码或您对代码所做的任何其他更改以使其正常工作!

标签: python django single-page-application pjax


【解决方案1】:

确保您已将 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

【讨论】:

  • 我所做的与问题中描述的完全相似。我添加了django.core.context_processors.request。我应该在pjax_base.html 中写些什么?它仍然无法正常工作。我是 pjax 的新手,我对 jquery-pjax 感到困惑,即 django-easy-pjax 应用程序是一个帮助程序,它可以轻松地将 jquery-pjax 与您的 Django 1.5 集成。那么在使用easy-pjax 时,我是否还必须配置服务器端的东西?我正在尝试几个小时,请帮助我:(如果我的疑问不清楚,请发表评论
  • @AshishGupta 很抱歉回复晚了。我已经忘记了我所知道的关于 django-easy-pjax 的一切,哈哈。原因是因为有大量的 SPA 引擎比这个 hack 更好,而
  • 没关系 :) 最好忘记这一点并选择一个更好的选项 :P 即使我离开它并选择 django-rest 和 angularjs :)
【解决方案2】:

我确定你不再需要这个了。但你应该添加这个: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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多