I’m looking for a better way to code:
My Code is,
@login_required
def updateEmInfo(request):
userProfile = request.user.get_profile()
if request.POST.__contains__('userType'):
userType = request.POST['userType']
else:
userType = None
if request.method == 'POST':
~~~~~~~~
If I code as userType = request.POST['userType'], then I get an error if userType is not equal.
I don’t think it is good idea to to use the __contains__ method, is there a better way to write this code?
Something easy like the following
userType = request.POST['userType'] ? request.POST['userType'] : None
you can use
getrequest.POST.get('userType').