I have a form in django template. In the view that gets data from this form, I need to check if the entry is ‘str’ or ‘int’. If it’s ‘str’, I have to raise an error. But when I check the type of the entry by using:
pr = request.GET['pr no']
print "Type of PR:%s" % type(pr)
irrespective of the ‘pr’ being string or integer, type() function returns ‘unicode’. How do I go about it?
Thanks
Well, obviously
.GET['pr no']always returns aUnicodeobject then.Whether that string contains an integer can be tested:
or
Alternatively, you could do
or check for any valid number: