2

私は自分のプロジェクトにdjango-endlessページ付けを実装しようとしています。単純なページ付けは(「もっと見る」で)機能しますが、Twitterスタイル(ajaxベース)は私に問題を与えています。

これは私の見解です:

@page_template('userena/profil_page.html')  # just add this decorator
def public_details(request, username=None,
    template = 'userena/profil.html', extra_context=None):
    user = get_object_or_404(get_user_model(), username__iexact=username)

    userObjekat = User.objects.get(username=username)
    user_profil = userObjekat.get_profile()

    context = {
        'projekti': user_profil.projekat_set.all(),
    }
    if extra_context is not None:
        context.update(extra_context)

    return userena_views.profile_detail(request, extra_context=context, username=username, template_name='userena/profil.html')

提案されているように、私のテンプレートは「メイン」とAJAXの2つの部分に分かれています。これは、_pageテンプレートをロードするメインテンプレートの一部です。

</li>
{% include page_template %}
</li>

および_pageテンプレートGETSINCLUDED-コンテンツを表示できます。

_ページテンプレート:

{% load endless %}
<li id="projektiTab">
    <div class="ten columns">
    <ul class="accordion">
    {% paginate projekti %}
    {% for projekat in projekti %}
    <li>                        
        <div class="title">
            <h6> {{ projekat.naziv }}</h6>
        </div>
        <div class="content">
            <p>{{ projekat.opis }}</p>
        </div>
    </li>
    {% endfor %}
    {% show_more %}
<li>
</div>
</li>

Javascriptも読み込まれ(STATIC_URLが機能しています)、使用するページソースでは次のようになります。

<script src="/static/js/endless-pagination.js"></script>
        <script>
        $.endlessPaginate({
            paginateOnScroll: true,
            paginateOnScrollChunkSize: 5
        });
        </script>

結局、スクロールによるページネーションは機能していません。私は何が間違っているのですか?

4

1 に答える 1

2

もちろん、私が犯した「小さな」間違いがいくつかありました。それは取るに足らないように見えましたが、そうではありません。

メインテンプレート、またはpage_templateを保持する親テンプレートには、次のようなものが含まれている必要があります。

<div class="endless_page_template">
    {% include page_template %}

    {% block js %}
    {{ block.super }}
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script src="{{ STATIC_URL }}js/endless-pagination.js"></script>
    <script>$.endlessPaginate();</script>
    {% endblock %}
</div>

それで、それは私が昨日見落としたその特定のクラスとのdivにあるに違いありません。

page_templateは次のようになります。

{% load endless %}

{% paginate projekti %}
{% for projekat in projekti %}
   {{ projekat.name }}
{% endfor %}
{% show_pages %}

もちろん、これはいくつかのHTML(私の場合はZurb Foundationのアコーディオン要素)できれいにすることができます。そして最後になりましたが、重要なことですが、ビュー:

@page_template('userena/profil_strana.html')  # name of the page_template
def public_details(request, username=None,
    template = 'userena/profil.html', extra_context=None):

    userObjekat = User.objects.get(username=username) # getting user object
    user_profil = userObjekat.get_profile() # getting user's profile
    context = {
        'projekti': user_profil.projekat_set.all(), # and a list of objects to iterate thru
    }
    if extra_context is not None:
        context.update(extra_context)

    return userena_views.profile_detail(request, extra_context=context, username=username, template_name=template)

そしてそれは動作します。

于 2013-03-18T15:55:04.060 に答える