django: generic class view + POST = HTTP 405 (Method not allowed)
Asked Answered
L

1

13

Recently I've started converting some of the view functions to Generic Views. Converting the function which was expected to handle POST request (via AJAX form) results in "405 Method not allowed" HTTP exception. I'm sure is not about CSRF: Ajax sends valid token, changing the generic view back to view function (in the test case, they're essentially the same) fixes the problem, and - lastly - for testing purposes, I've disabled CSRF middleware. Did anyone experienced similar problems?

Lindley answered 19/12, 2011 at 15:24 Comment(0)
C
17

I suppose you are using class-based views. If so then you need to define post method in your view or use mixin which does it (django.views.generic.edit.ProcessFormView for example). If you want to fully understand why this is necessary then look at dispatch method of django.views.generic.base.View.

Caulk answered 19/12, 2011 at 17:43 Comment(1)
I didn't end my url with slash at the end. That was my issue.Accoucheur

© 2022 - 2024 — McMap. All rights reserved.