【问题标题】:Does not exist. No exception supplied error不存在。没有异常提供错误
【发布时间】:2013-05-17 09:22:26
【问题描述】:

我有以下基于类的视图。

class AllPluginsView(ListView):
    queryset = get_models(get_app('plugins'))
    template_name="console/plugins/plugins.html"
    context_object_name = "objects"

和下面的模板,

{% for object in objects %}
    <tr>
    {% if object %}
        <td>{{ object }}</td>
    {% endif %}
    </tr>
{% endfor %}

当我请求页面时,我收到 DoesNotExist at /path/to/plugins No exception supplied. 错误。有什么想法吗?

urlpatterns = patterns('',
    url(r'^$', AllPluginsView.as_view(),name='all-plugins'),
)

【问题讨论】:

  • queryset 需要是一个查询集,而不是一个列表(由get_models() 返回(我从未见过它这样做,所以我可能错了)
  • get_models 返回一个列表。有没有办法将列表转换为查询集
  • 也试过class AllPluginsView(View): template_name="console/plugins/plugins.html" context_object_name = "objects" def get(self,request, *args, **kwargs): plugins= get_models(get_app('plugins')) return render(request, self.template_name, {'objects':plugins})同样的结果
  • 应该context_object_name = "objects"context_object_name = "object" 吗?

标签: python django django-templates django-views django-class-based-views


【解决方案1】:

也许是进口订单?尝试改用get_queryset

class AllPluginsView(ListView):
    template_name="console/plugins/plugins.html"
    context_object_name = "objects"

    def get_queryset(self):
        return get_models(get_app('plugins'))

【讨论】:

    猜你喜欢
    • 2013-06-15
    • 2014-02-17
    • 2018-04-24
    • 2016-05-28
    • 2017-09-13
    • 2018-07-17
    • 1970-01-01
    • 2018-03-05
    • 1970-01-01
    相关资源
    最近更新 更多