Django 错误:“QueryDict”对象没有属性“_meta”;
我对 django 很陌生,所以这可能是一个菜鸟问题。 我正在尝试重用 django admin 的更改列表视图。我创建了一个管理模型,并希望向更改列表模板提供这些对象的列表。在我看来,我有:
def placements(request):
partner_id = request.session.get('partner_id', 0)
self = PlacementAdmin(request.GET, Placement.objects.filter(partner=partner_id))
return render_to_response('publisher/placement/change_list.html', {'cl': self})
当我尝试从浏览器中点击此功能时,出现此错误: “QueryDict”对象没有属性“_meta” 谁能告诉我错误是什么,或者提供一种更简单的方法来完成此操作,以防我完全走上错误的轨道。
这是完整的跟踪:
Request Method: GET
Request URL: http://localhost:8080/publisher/
Django Version: 1.3 beta 1
Exception Type: AttributeError
Exception Value:
'QueryDict' object has no attribute '_meta'
Exception Location: /Users/imran/django_env/lib/python2.6/site-packages/django/contrib/admin/options.py in __init__, line 278
Python Executable: /Users/imran/django_env/bin/python
Python Version: 2.6.1
Python Path:
['.',
'.',
'/Users/imran/Workspaces/publisher/django/pub_admin',
'/Users/imran/django_env/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
'/Users/imran/django_env/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg',
'/Users/imran/django_env/lib/python26.zip',
'/Users/imran/django_env/lib/python2.6',
'/Users/imran/django_env/lib/python2.6/plat-darwin',
'/Users/imran/django_env/lib/python2.6/plat-mac',
'/Users/imran/django_env/lib/python2.6/plat-mac/lib-scriptpackages',
'/Users/imran/django_env/Extras/lib/python',
'/Users/imran/django_env/lib/python2.6/lib-tk',
'/Users/imran/django_env/lib/python2.6/lib-old',
'/Users/imran/django_env/lib/python2.6/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/Users/imran/django_env/lib/python2.6/site-packages']
I am very new to django so this is probably a noob question.
I am trying to reuse django admin's change list view. I've created a admin model and want to provide the changelist template a list of these objects. In my view I have:
def placements(request):
partner_id = request.session.get('partner_id', 0)
self = PlacementAdmin(request.GET, Placement.objects.filter(partner=partner_id))
return render_to_response('publisher/placement/change_list.html', {'cl': self})
I get this error when I try to hit this function from a browser:
'QueryDict' object has no attribute '_meta'
Could anyone tell me what the error is or provide an easier way to accomplish this in case I am on the wrong track completely.
Heres the complete trace:
Request Method: GET
Request URL: http://localhost:8080/publisher/
Django Version: 1.3 beta 1
Exception Type: AttributeError
Exception Value:
'QueryDict' object has no attribute '_meta'
Exception Location: /Users/imran/django_env/lib/python2.6/site-packages/django/contrib/admin/options.py in __init__, line 278
Python Executable: /Users/imran/django_env/bin/python
Python Version: 2.6.1
Python Path:
['.',
'.',
'/Users/imran/Workspaces/publisher/django/pub_admin',
'/Users/imran/django_env/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
'/Users/imran/django_env/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg',
'/Users/imran/django_env/lib/python26.zip',
'/Users/imran/django_env/lib/python2.6',
'/Users/imran/django_env/lib/python2.6/plat-darwin',
'/Users/imran/django_env/lib/python2.6/plat-mac',
'/Users/imran/django_env/lib/python2.6/plat-mac/lib-scriptpackages',
'/Users/imran/django_env/Extras/lib/python',
'/Users/imran/django_env/lib/python2.6/lib-tk',
'/Users/imran/django_env/lib/python2.6/lib-old',
'/Users/imran/django_env/lib/python2.6/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages',
'/Users/imran/django_env/lib/python2.6/site-packages']
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好在发布问题时发布回溯错误!
也就是说,错误来自于您将
request.GET
传递给了不期望的ModelAdmin
管理对象。不过,您还有很长的路要走,因为您正在尝试使用神奇的change_list视图模板,该模板是由一组更神奇的、未记录的模板标签操作的,这些模板标签通常不会出现在同一个模板中。句子为django新手。
我认为你走错了路,只是因为 django 的管理不容易被黑客入侵。
至少,您必须在模板中为
cl
变量传递一个ChangeList
对象。如果您确实想这样做,我能给的唯一建议是查看 django.contrib.admin.options.ModelAdmin.changelist_view() ,因为这就是您要复制的内容。
说真的,我想劝你不要这么做。与 Django 一起工作实际上非常有趣!
It's best to post the traceback error when posting a question!
That said, the error comes from you passing
request.GET
to aModelAdmin
admin object which isn't expecting it.You have a long road of troubles ahead of you though, as you're trying to use the magical change_list view template which is operated on by a collection of even more magical, undocumented template tags, which just doesn't normally appear in the same sentence as new to django.
I think you're on the wrong track simply because django's admin is not easy to hack into.
At a minimum, you'd have to pass in your template a
ChangeList
object for thecl
variable.If you really want to do this, the only advice I can give is to take a look at
django.contrib.admin.options.ModelAdmin.changelist_view()
since that's what you're trying to replicate.Seriously though I'd like to talk you out of this. Django's actually really fun to work with!