Django + elpaginaton + ajax,没有使用detailview类

时间:2018-11-12 18:31:59

标签: python ajax django

仅在启用

的情况下,我的DetailView才会打开新页面
  

{%load el_pagination_tags%}

     

{%lazy_paginate base_publications%}

但是,如果我禁用这些标签,则一切正常(除了无休止的c分页)。

这里有个例子:

views.py

class IndexPublication(AjaxListView):   
      context_object_name = 'base_publications'
      template_name = 'Post/base.html'
      page_template='Post/base_list.html' 

      def get_queryset(self, **kwargs):         
          if self.request.method == 'GET':
             return Post_model.objects.order_by('-published_date')

  class PublicationDetail(DetailView):  
       model = Post_model
       template_name = 'Post/post_detail.html'

Base_list.html

{% load el_pagination_tags %}

{% lazy_paginate base_publications %}

<ul class="grid-container">
    {% for post in base_publications %}

    <li>
        <a class="navbar" href="{% url 'publications:detail_publication' pk=post.id %}">
        <h3 class="title">{{ post.preview_title|linebreaks }}</h3> 
        <p class="text">{{ post.preview_text|safe }}</p>
        </a>
        <img class='preview'src='{{ MEDIA_URL }}{{ post.preview_photo }}'>
        {{ post.published_date }}
    </li>
    {% endfor %}
</ul>

Post_detail.html

{% extends 'Post/base.html' %}

{% block content %}
    <div class="post">
        {{ object.main_title }}
        {{ object.main_textbox|safe }}
        {% if object.published_date %}
            <div class="date">
                {{ object.published_date }}
            </div>
        {% endif %}
    </div>
{% endblock %}

在使用el_pagination时,如果我尝试单击自己的网址,我就会出错。

VariableDoesNotExist at /post/15/
Failed lookup for key [base_publications] in [{'True': True, 'False': False, 'None': None}, {}, {}, {'object': <Post_model: #БагажЗнаний КАК НЕ БОЯТЬСЯ ЛЕТАТЬ НА САМОЛЕТАХ>, 'post_model': <Post_model: #БагажЗнаний КАК НЕ БОЯТЬСЯ ЛЕТАТЬ НА САМОЛЕТАХ>, 'view': <Post.views.PublicationDetail object at 0x05146B50>}]
Request Method: GET
Request URL:    http://192.168.1.2:8080/post/15/
**Django Version:   2.1.3**
Exception Type: VariableDoesNotExist
Exception Value:    
Failed lookup for key [base_publications] in [{'True': True, 'False': False, 'None': None}, {}, {}, {'object': <Post_model: blabla, 'post_model': <Post_model: blbla>, 'view': <Post.views.PublicationDetail object at 0x05146B50>}]
Exception Location: C:\Users\poker king\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\template\base.py in _resolve_lookup, line 850
Python Executable:  C:\Users\poker king\AppData\Local\Programs\Python\Python36-32\python.exe
**Python Version: 3.6.7**

**Error during template rendering**
In template C:\seniortravel\Post\templates\Post\base_list.html, error at line 3

Failed lookup for key [%s] in %r
1   {% load el_pagination_tags %}
2   
3   {% lazy_paginate base_publications %}

我有点新。并放弃谷歌搜索这个问题。 谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

问题出在base.html中-我使用{%include%},但是在base_list中更改为{extends base.html}后,一切正常。