django - Sending A post request from ajax to a python function but receiving a GET request? -


i new django.i sending ajax post request python function in turn stores data in variables ajax , return httpresponse .so checked request.method in python coming get.

$.ajax({   url:"create_post/",   type:"post",    data : {f_name: first_name ,l_name: last_name,eadd: email , password: pass},   success:function(){     window.location.href="create_post/";     console.log ("success")   },   cache:false,   failure: function(errmsg) {     alert(errmsg);   } }); 

this ajax request.

its sending data function .

def create_post(request):     if request.method == 'get':         first_name=request.get['f_name'];         last_name=request.get["l_name"];         email_address=request.get["eadd"];         pass=request.get["password"];     return httpresponse("<html><body>hi me .</body></html>"); 

when checked return(request.method) giving me get.

can 1 explain behavior? , in function have request.method==get in scenario django giving me internal server 500 error.

thanks

your ajax method post, think views.py may try this

def create_post(request):     if request.method == 'post':         first_name=request.post['f_name']         last_name=request.post["l_name"]         email_address=request.post["eadd"]         pass=request.post["password"]     return httpresponse("<html><body>hi me .</body></html>") 

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -