Search code examples
djangoposthttp-status-code-405

Django 1.7.2 POST without using FormView


Fellows, I am now implementing simple app using Django 1.7.2 I am looking for handling post method without using FormView.

I tried to search every page in Websites, but I could not solve this problem

Every time I tried to solve it, I got 405 Error(Method not Allowed)

This is code from gist I pasted it. URL : https://gist.github.com/BOBTommy/aeb96a6e9413fddc85a2

If you can't access it, please tell me that. I will paste this post.


Solution

  • Your url patterns are messed up, and your form redirects to the LoginView, not your LoginProcessView. This will fix it:

    urls.py

    urlpatterns = patterns('',
        url(r'^$', LoginView.as_view(), name="login"),
        url(r'^login_process/$', LoginProcessView.as_view(), name="login_process"),
    )
    

    login.html (Remove slash before login_process, add one after. Or better yet, use the url template tag).

    ...
    <form class="form-horizontal" role="form" action="login_process/" method="POST">
    ...