私はコーディングするためのより良い方法を探しています:
私のコードは、
@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':
~~~~~~~~
次のようにコーディングすると、等しくないuserType = request.POST['userType'],
場合にエラーが発生します。userType
メソッドを使用するのは良い考えではないと思いますが__contains__
、このコードを書くためのより良い方法はありますか?
次のような簡単なもの
userType = request.POST['userType'] ? request.POST['userType'] : None