在 django 中使用通用视图时出现问题
我目前正在使用 django 通用视图,但有一个我无法解决的问题。
使用delete_object时,我得到一个TypeError异常:
delete_object() takes at least 3 non-keyword arguments (2 given)
这是代码(我省略了文档字符串和导入):
views.py
def delete_issue(request, issue_id):
return delete_object(request,
model = Issue,
object_id = issue_id,
template_name = 'issues/delete.html',
template_object_name = 'issue')
urls.py
urlpatterns = patterns('issues.views',
(r'(?P<issue_id>\d+)/delete/$', 'delete_issue'),
)
其他通用视图(object_list、create_object等)可以很好地使用这些参数。我遇到的另一个问题是,当使用 create_object() 函数时,它提到了一些有关 CSRF 机制的内容,那是什么?
I'm currently working with django generic views and I have a problem I can't figure out.
When using delete_object I get a TypeError exception:
delete_object() takes at least 3 non-keyword arguments (2 given)
Here is the code (I have ommited docstrings and imports):
views.py
def delete_issue(request, issue_id):
return delete_object(request,
model = Issue,
object_id = issue_id,
template_name = 'issues/delete.html',
template_object_name = 'issue')
urls.py
urlpatterns = patterns('issues.views',
(r'(?P<issue_id>\d+)/delete/
The other generic views (object_list, create_object, etc.) work fine with those parameters. Another problem I have is when using the create_object() function, it says something about a CSRF mechanism, what is that?
, 'delete_issue'),
)
The other generic views (object_list, create_object, etc.) work fine with those parameters. Another problem I have is when using the create_object() function, it says something about a CSRF mechanism, what is that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要提供
post_delete_redirect
,这意味着 url,在删除对象后应将用户重定向到该 URL。您可以在视图签名中找到它:You need to provide
post_delete_redirect
, this means url, where user should be redirected after object is deleted. You can find this in view signature: