request.POST.get is not working

2,333 views
Skip to first unread message
Message has been deleted

bharathi

unread,
Sep 10, 2008, 6:25:49 AM9/10/08
to Django users
Hi,
I am using Django1.0
In this request.POST.get() is not Working..It Gives empty value

My Views is:

def addtask(request):
r=HttpResponse()
if request.method == 'POST':
task = request.POST.get('task')
a = "taskname"+ str(task)
r.write(a)
return r

My Template is :


function addtasks()

{

var task=document.getElementById("task").value;
$.ajax({

url: "/simple2dos/addtask/",

type: "POST",

data: "val=1&task="+task,

success: function(feedback){
alert(feedback);
}
}):
}
<input type="text" id="task" name="task" value="">
<input type="button" name="submit1" value="Submit"
onclick="addtasks();">




If i use GET instead of POST means its working Fine..

Please Help Me..

Thanks
Bharathi

LaundroMat

unread,
Sep 10, 2008, 7:36:23 AM9/10/08
to Django users
On Sep 10, 12:25 pm, bharathi <bharathimohan1...@gmail.com> wrote:
> Hi,
>   I am using Django1.0
>   In this request.POST.get() is not Working..It Gives empty value
> (snip)

What about request.POST['task']?

bharathi

unread,
Sep 10, 2008, 7:50:00 AM9/10/08
to Django users
Hi LaundroMat,

I tried request.POST['task'] .. But that also not working..
It shows
" MultiValueDictKeyError at /addtask/
&quot;Key &#39;task&#39; not found in &lt;QueryDict: {}&gt;&quot;"

Wat i do now?
Help me

Thanks,
Bharathi

LaundroMat

unread,
Sep 10, 2008, 11:46:41 AM9/10/08
to Django users


On Sep 10, 1:50 pm, bharathi <bharathimohan1...@gmail.com> wrote:
> Hi LaundroMat,
>
>     I tried request.POST['task'] .. But that also not working..
>    It shows
>    " MultiValueDictKeyError at /addtask/
>    &quot;Key &#39;task&#39; not found in &lt;QueryDict: {}&gt;&quot;"
>
>  Wat i do now?
> Help me

Well, this means request.POST contains no key 'task', which means it
wasn't POSTed by your script in the first place. I don't know enough
of Javascript to help you there.

David Reynolds

unread,
Sep 11, 2008, 4:54:45 AM9/11/08
to Django users
Check your javascript is being called, by sticking an alert in the
function?
Check your development log to see if the post is going through
correctly?
Print the contents of request.POST to see if the data is getting
through?

All/one of these should be useful for debugging what is going on.

--
David Reynolds
da...@reynoldsfaily.org.uk

theaellen

unread,
Oct 8, 2008, 1:32:25 AM10/8/08
to Django users
Hope you have solved this problem already. I ran into a similar
problem today while trying to use something like
task = request.POST.get('task')
which I thought should work since it worked for GET. I have a large
list to pass back and GET did not have enough room.
I ended up doing something like this:

def addtask(request):
post = request.POST.copy()
task = post['task']
a = "taskname" + str(tsk)
r.write(a)
return r

notice that I used post=request.POST.copy()
This helped my solution considerably.



On Sep 10, 6:25 am, bharathi <bharathimohan1...@gmail.com> wrote:
> Hi,
> I am using Django1.0
> In thisrequest.POST.get() is not Working..It Gives empty value
>
> My Views is:
>
> def addtask(request):
> r=HttpResponse()
> ifrequest.method == 'POST':
> task=request.POST.get('task')
> a = "taskname"+ str(task)
> r.write(a)
> return r
>
> My Template is :
>
> function addtasks()
>
> {
>
> vartask=document.getElementById("task").value;
> $.ajax({
>
> url: "/simple2dos/addtask/",
>
> type: "POST",
>
> data: "val=1&task="+task,
>
> success: function(feedback){
> alert(feedback);
> }
> }):}
>
> <input type="text" id="task" name="task" value="">
> <input type="button" name="submit1" value="Submit"
> onclick="addtasks();">
>
> If i use GET instead ofPOSTmeans its working Fine..

theaellen

unread,
Oct 8, 2008, 1:32:25 AM10/8/08
to Django users
Hope you have solved this problem already. I ran into a similar
problem today while trying to use something like
task = request.POST.get('task')
which I thought should work since it worked for GET. I have a large
list to pass back and GET did not have enough room.
I ended up doing something like this:

def addtask(request):
post = request.POST.copy()
task = post['task']
a = "taskname" + str(tsk)
r.write(a)
return r

notice that I used post=request.POST.copy()
This helped my solution considerably.



On Sep 10, 6:25 am, bharathi <bharathimohan1...@gmail.com> wrote:
> Hi,
> I am using Django1.0
> In thisrequest.POST.get() is not Working..It Gives empty value
>
> My Views is:
>
> def addtask(request):
> r=HttpResponse()
> ifrequest.method == 'POST':
> task=request.POST.get('task')
> a = "taskname"+ str(task)
> r.write(a)
> return r
>
> My Template is :
>
> function addtasks()
>
> {
>
> vartask=document.getElementById("task").value;
> $.ajax({
>
> url: "/simple2dos/addtask/",
>
> type: "POST",
>
> data: "val=1&task="+task,
>
> success: function(feedback){
> alert(feedback);
> }
> }):}
>
> <input type="text" id="task" name="task" value="">
> <input type="button" name="submit1" value="Submit"
> onclick="addtasks();">
>
> If i use GET instead ofPOSTmeans its working Fine..
Reply all
Reply to author
Forward
0 new messages