django无尽的分页不是在生产中工作,而是在开发中工作

时间:2013-04-09 17:01:40

标签: django django-endless-pagination

我正在为我的网站使用django-endless-pagination和twitter风格,它在开发中工作得很好但是当我转向生产时它甚至没有显示条目。我正在使用webfaction,下面列出了我已经采取的行动。

1)PYTHONPATH = $ HOME / webapps / csiop / lib / python2.7 easy_install-2.7 --install-dir = $ HOME / webapps / csiop / lib / python2.7 --script-dir = $ HOME / webapps / csiop / bin django-endless-pagination 2)python manage.py syncdb 3)在settings.py

中也将infinite_pagination添加到settings.py及以下
 PAGINATION_SETTINGS = {
  'PAGE_RANGE_DISPLAYED': 10,
  'MARGIN_PAGES_DISPLAYED': 2,
 }

4)我的views.py更改为如下所示

   def homepage(request):
       item_list = items.objects.filter(show_on_website=True)
       template = 'homepage.html'
       page_template = 'home_page_index.html'

       if request.is_ajax():
             template = page_template

       return render_to_response(template,
         {'page_template': page_template,
         'item_list': item_list},
       context_instance=RequestContext(request))

5)我的模板如下所示。

Homepage.html: -

    <h2>Entries:</h2>
    {% include page_template %}

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

home_page_index.html: -

   {% load endless %}

   {% lazy_paginate entries %}
      {% for entry in entries %}
        {# your code to show the entry #}
      {% endfor %}
   {% show_more " " %}

上面的代码在我的开发中完全正常,但在生产中却没有。 有人可以帮我解决的问题吗?

编辑: - 如果我在我的开发环境中将调试模式设置为False,则会出现以下错误。我在网站上也使用django-seo,它似乎在抱怨,但我不确定错误到底是什么。

  Traceback (most recent call last):
  File            "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
  self.result = application(self.environ, self.start_response)
  File "/Users/django1.5/django1.5_ve/lib/python2.7/site-  packages/django/core/handlers/wsgi.py", line 255, in __call__
  response = self.get_response(request)
  File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/core/handlers/base.py", line 178, in get_response
  response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/core/handlers/base.py", line 224, in handle_uncaught_exception
  return callback(request, **param_dict)
  File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/utils/decorators.py", line 91, in _wrapped_view
  response = view_func(request, *args, **kwargs)
  File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/views/defaults.py", line 41, in server_error
   return http.HttpResponseServerError(template.render(Context({})))
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/template/base.py", line 140, in render
   return self._render(context)
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
   return self.nodelist.render(context)
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/template/base.py", line 830, in render
   bit = self.render_node(node, context)
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/template/base.py", line 844, in render_node
   return node.render(context)
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/template/loader_tags.py", line 124, in render
   return compiled_parent._render(context)
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
   return self.nodelist.render(context)
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/template/base.py", line 830, in render
   bit = self.render_node(node, context)
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/django/template/base.py", line 844, in render_node
   return node.render(context)
   File "/Users/django1.5/django1.5_ve/lib/python2.7/site-packages/rollyourown/seo/templatetags/seo.py", line 25, in render
   raise template.TemplateSyntaxError(msg)
   TemplateSyntaxError: {% get_metadata %} needs some path information.
    Please use RequestContext with the django.core.context_processors.request context  processor.
    Or provide a path or object explicitly, eg {% get_metadata for path %} or {%        get_metadata for object %}
   [09/Apr/2013 18:22:49] "GET / HTTP/1.1" 500 59

由于

2 个答案:

答案 0 :(得分:1)

当您关闭调试模式时,Django会停止为您处理静态文件。在远程主机上,您需要在设置和manage.py collectstatic中设置STATIC_ROOT路径。您还可以查看this question

答案 1 :(得分:0)

我已经使用pip重新安装了django-endless-pagination,而不是简单安装,现在工作正常。看起来问题是因为我之前安装了easy-install之前没有-Z。