渲染时捕获 KeyError:“opts”在管理界面中
我开始使用自定义模板制作自定义管理视图。我创建了模板,通过内置的change_form.html模板、表单、视图和url进行扩展。我在扩展版本中更改了原始模板的 {% block form_top %}
,将我的表单传递到那里。当我查看页面的 url 时,出现错误:
渲染时捕获 KeyError:管理界面中的“opts”。
这发生在 {% Submit_row %}
模板标记中模板的第 60 行。完整的回溯位于http://dpaste.com/hold/612843/。还有什么不够的吗?哪里找不足?
编辑:
{% extends "admin/change_form.html" %}
{% block form_top %}
{{ form.as_p }}
{% endblock %}
编辑:
def order_cats(request):
form = OrderCats()
return direct_to_template(request, 'admin/shivaapp/order_cats.djhtml',
{'form': form})
I start to make custom admin view, with custom template. I created template, extended by built-in change_form.html template, form, view and url. I changed {% block form_top %}
of orig template in my extended version, passing my form in there. When I view the url of my page, I got an error:
Caught KeyError while rendering: 'opts' in admin interface.
This happens in line 60 of template in {% submit_row %}
template tag. Full traceback in there http://dpaste.com/hold/612843/. What is there is not enough? Where to look the lack?
Edit:
{% extends "admin/change_form.html" %}
{% block form_top %}
{{ form.as_p }}
{% endblock %}
Edit:
def order_cats(request):
form = OrderCats()
return direct_to_template(request, 'admin/shivaapp/order_cats.djhtml',
{'form': form})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mkriheli 是正确的,这个 url 被呈现为change_form而不是change_list,这有点奇怪。显然您在
shivaapp/admin_views.py
中自定义了管理视图,但做得不正确。mkriheli is correct, there is something odd with this url being rendered as a change_form rather than a change_list. Apparently you customised the admin view in
shivaapp/admin_views.py
, but did so incorrectly.错误是我需要覆盖
{% block content %}
,而不是{% block form_top %}
。Mistake was that I needed to override
{% block content %}
, but not{% block form_top %}
.