-1

I failed to get the values of textarea in django, i pasted html code below.

<textarea id='msg' name='message' class='form-control' rows=10 cols=30/>

<textarea id='msg' name='message' class='form-control' rows=10 cols=30/>
srinivas
  • 53
  • 8
  • can you show ur views.py code – rahul.m Feb 11 '19 at 05:54
  • You said you can not read it? I'm not sure where in your view you are using this `message = request.post['message'] ` , so in general if you want it for a query set then use `message = request.GET.get['message'] ` or if you want it for saving in database, use `message = request.POST.get['message'] ` – Bidhan Majhi Feb 11 '19 at 06:05
  • message type is textarea type before reading the message i am reading To, subject text field values as request.POST['TO'], request.POST['subject'] these two are type fields these are not throwing error problem is textarea type – srinivas Feb 11 '19 at 06:25
  • @srinivas so do you have multiple textarea with same name parameter? – Khamidulla Feb 11 '19 at 08:09
  • Thank you, Mr @Khamidulla I found the problem yes I have multiple text area with the same name. – srinivas Feb 16 '19 at 05:23
  • @srinivas I updated my answer. Please check it. – Khamidulla Feb 18 '19 at 01:25
  • Thank You, Mr @Khamidulla it's working now – srinivas Feb 18 '19 at 06:18

3 Answers3

1

You should get your variable as follows if it is POST request:

request.POST.getlist('message[]')

Read documenation here.

Khamidulla
  • 2,927
  • 6
  • 35
  • 59
1

Try to use:

request.POST.get('message', None)

You also can find here reference here: django MultiValueDictKeyError error, how do I deal with it

Gourav
  • 2,746
  • 5
  • 28
  • 45
0

Please use this

request.POST.getlist('message')

where message is the name of your html attribute.