-2

I have a input field as follows

<input type="text" name="first_name"/>

when I call it from view.py

first_name = request.POST['first_name'],

I get value as following

(u'sazzad',)

here sazzad is my input but i get that extra part (u'',)

how to fix this??

LynAs
  • 6,407
  • 14
  • 48
  • 83
  • possible duplicate of [What does the 'u' symbol mean in front of string values?](http://stackoverflow.com/questions/11279331/what-does-the-u-symbol-mean-in-front-of-string-values) – rnevius Apr 15 '15 at 11:45
  • 2
    You should not access data directly from request.POST but through a django form module. See https://docs.djangoproject.com/en/1.8/topics/forms/ – luc Apr 15 '15 at 11:49
  • I am not binding it to any db table. do i need to go through this process @luc – LynAs Apr 15 '15 at 11:58
  • 3
    It has nothing to do with db tables. Forms provide a lot of useful functionality around validation and cleaning; you should use them unless you have a good reason not to. – Daniel Roseman Apr 15 '15 at 12:01
  • @Sazzad I fully agree with Daniel comment – luc Apr 15 '15 at 12:10

1 Answers1

4

You have accidentally added a comma to the end of the line:

first_name = request.POST['first_name'],
                                       ^ trailing comma

That means that first_name is a tuple (u'sazzad',), instead of a string u'sazzad'.

You should remove this comma.

As @rnevius says in the comments, the u'' prefix just means that it's a unicode string, you don't have to worry about this.

Alasdair
  • 298,606
  • 55
  • 578
  • 516