django POST returning Internal Server 500 error
<p>I am trying to POST a request to a django view but it keeps returning <code>INTERNAL SERVER ERROR 500</code>.</p>

<p>My ajax post:</p>

<pre><code>$.ajax({
    url : "/loginAction/",
    type : "POST",
    async : false,
    data : {action:'loginAction',
            email:email,
            password:password},

    success : function(response) {
        $.niftyNoty({
            type:"success",icon:"",title:"Login Successful. Redirecting....",container:"floating",timer:5000
        });
    },

    error : function(xhr,errmsg,err) {
        console.log(xhr.status + ": " + xhr.responseText);
        $.niftyNoty({
            type:"danger",icon:"",title:"Wrong Email OR Password",container:"floating",timer:5000
        });
    }
});
</code></pre>

<p>My django view:</p>

<pre><code>def loginAction(request):
    print "Its workjing"
    if request.method == 'POST' and 'loginButton' in request.POST:
        email = request.POST.get('email')
        password = request.POST.get('password')

        print email, password

        return HttpResponse(json.dumps({}),content_type="application/json")
</code></pre>

<p>My urls.py</p>

<pre><code>urlpatterns = [
            url(r'^', views.loginPage, name='loginPage'),
            url(r'^loginAction/', views.loginAction, name='loginAction')
        ]
</code></pre>

<p>The ajax POST is not hitting the django view. It is not printing <code>Its working</code> in console. So its not returning the json response to ajax call. I also tried normal form POST but same result. I am using django 1.9.2. I cant figure out why this error?</p>

<p>It returns this error code:</p>

<pre><code>Internal Server Error: /loginAction/
Traceback (most recent call last):
  File "/home/manish/Desktop/admin_picknbox/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 158, in get_response
    % (callback.__module__, view_name))
ValueError: The view login_app.views.loginPage didn't return an HttpResponse object. It returned None instead.
</code></pre>

<p>EDIT:
ajax Header:</p>

<pre><code>jQuery(document).ready(function($){
    $.ajaxSetup({
        beforeSend: function(xhr, settings) {
            if (!csrfSafeMethod(settings.type) &amp;&amp; !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
        }
    });
});
</code></pre>