开发者

Problem using generic views in django

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/$', '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?


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'):
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜