在 django 中使用通用视图时出现问题

发布于 2024-09-11 14:15:11 字数 782 浏览 5 评论 0原文

我目前正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗忘曾经 2024-09-18 14:15:11

您需要提供 post_delete_redirect,这意味着 url,在删除对象后应将用户重定向到该 URL。您可以在视图签名中找到它:

def delete_object(request, model, post_delete_redirect, object_id=None,
        slug=None, slug_field='slug', template_name=None,
        template_loader=loader, extra_context=None, login_required=False,
        context_processors=None, template_object_name='object'):

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:

def delete_object(request, model, post_delete_redirect, object_id=None,
        slug=None, slug_field='slug', template_name=None,
        template_loader=loader, extra_context=None, login_required=False,
        context_processors=None, template_object_name='object'):
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文