gpt4 book ai didi

python - AttributeError at/'str' 对象没有属性 '_mptt_meta'

转载 作者:行者123 更新时间:2023-11-28 19:22:02 25 4
gpt4 key购买 nike

我正在使用 feinCMS 并将自定义内容添加到页面,并覆盖了自定义内容类中的渲染方法。渲染方法如下:

    return render_to_string('badge/categories.html', {'categories', self}, context_instance=kwargs.get('context'))

badge/categories.html 模板中的代码是:

    {% extends "feincms/base.html" %}
{% load feincms_page_tags %}
<h2> {{ feincms_page }}</h2>

{% for item in feincms_page.content.main %}
{{ item.render }}
{% endfor %}

页面的覆盖 url 是“/”。如果自定义内容没有添加到页面,它工作正常,但是一旦我添加它,它就会抛出以下错误:

    Template error:
In template /home/yogesh/programs/bw-election-badges/apps/templates/includes/top_menu.html, error at line 4
'str' object has no attribute '_mptt_meta'
1 : {% load feincmsext_extended_navigation_tags feincms_page_tags mptt_tags%}
2 : <div class="nav-collapse collapse">
3 : <ul class="nav">
4 : {% feincms_nav feincms_page level=1 depth=3 as navitems %}
5 : {% with navitems|siblings_along_path_to:feincms_page as navtree %}
6 : {% recursetree navtree %}
7 : <li> <a href="{{ node.get_absolute_url }}">{{ node.short_title }}</a></li>
8 : {% if children %}
9 : <div style="margin-left: 20px">{{ children }}</div>
10 : {% endif %}
11 : {% endrecursetree %}
12 : {% endwith %}
13 : </ul>
14 : </div><!--/.nav-collapse -->


Traceback:
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
140. response = response.render()
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/response.py" in render
105. self.content = self.rendered_content
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content
82. content = template.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
124. return compiled_parent._render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
63. result = block.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
156. return self.render_template(self.template, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render_template
138. output = template.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
54. result = self.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/defaulttags.py" in render
188. nodelist.append(node.render(context))
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render
84. output = self.filter_expression.resolve(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in resolve
578. obj = self.var.resolve(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in resolve
728. value = self._resolve_lookup(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in _resolve_lookup
779. current = current()
File "/home/yogesh/programs/bw-election-badges/apps/project/badge/models.py" in render
33. return render_to_string('badge/detail.html', {'badge': self}, context_instance=kwargs.get('context'))
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader.py" in render_to_string
172. return t.render(Context(dictionary))
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
124. return compiled_parent._render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
63. result = block.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
156. return self.render_template(self.template, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render_template
138. output = template.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/django/template/base.py" in render
1146. context[self.target_var] = func(*resolved_args, **resolved_kwargs)
File "/home/yogesh/programs/env/local/lib/python2.7/site-packages/feincms/module/page/templatetags/feincms_page_tags.py" in feincms_nav
57. mptt_opts = feincms_page._mptt_meta

Exception Type: AttributeError at /
Exception Value: 'str' object has no attribute '_mptt_meta'

最佳答案

您正试图在没有 FeinCMS 对象的情况下调用 FeinCMS 模板。

例如你有一个 include templates/includes/top_menu.html 需要缺少 feincms_page 变量,因此它无法生成菜单...

你应该改变一种方式,你如何做这个覆盖,有一个chapter in the docs详细说明此类集成。

关于python - AttributeError at/'str' 对象没有属性 '_mptt_meta',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23006016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com