python - django POST returning Internal Server 500 error -
i trying post request django view keeps returning internal server error 500
.
my ajax post:
$.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 }); } });
my django view:
def loginaction(request): print "its workjing" if request.method == 'post' , '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")
my urls.py
urlpatterns = [ url(r'^', views.loginpage, name='loginpage'), url(r'^loginaction/', views.loginaction, name='loginaction') ]
the ajax post not hitting django view. not printing its working
in console. not returning json response ajax call. tried normal form post same result. using django 1.9.2. cant figure out why error?
it returns error 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: view login_app.views.loginpage didn't return httpresponse object. returned none instead.
edit: ajax header:
jquery(document).ready(function($){ $.ajaxsetup({ beforesend: function(xhr, settings) { if (!csrfsafemethod(settings.type) && !this.crossdomain) { xhr.setrequestheader("x-csrftoken", csrftoken); } } }); });
it seems urls problem because in error appears loginpage
view called although go /loginaction/
. try add $
@ end of each regex below:
urlpatterns = [ url(r'^$', views.loginpage, name='loginpage'), url(r'^loginaction/$', views.loginaction, name='loginaction') ]
because appears first regex r'^'
captures url.
Comments
Post a Comment