我有视图功能,根据我给出的数据过滤对象,如果数据库中不存在过滤后的对象,则将对象添加到DB(我还没有编写添加功能)。如果已存在则显示错误。我使用ajax post请求从模板中获取数据。
#view.py
@csrf_exempt
def setUserInDB(request):
if request.method=="POST":
if request.POST.get('pname','u_id'):
pname = request.POST.get('pname')
u_id = request.POST.get('u_id')
user = userprofile.objects.get(pk=u_id)
pid = Project.objects.get(title=pname)
else:
u_id = None
pname = None
if request.POST.get('db_id','chkbox'):
db_id = request.POST.get('db_id')
db = Db_profile.objects.get(pk=db_id)
chkbox = request.POST.get('chkbox')
print chkbox
else:
db_id = None
chkbox = None
if Projectwiseusersetup.objects.filter(userid=user,project_id=pid,
db_profileid= db,setasdefaultproject=chkbox):
print "already exist"
elif (((Projectwiseusersetup.objects.filter(userid = user,project_id =
pid,db_profileid=db,setasdefaultproject=False)).exists()) and
(chkbox==True)):
print "FtoT"
elif Projectwiseusersetup.objects.filter(userid = user,project_id =
pid,db_profileid=db,setasdefaultproject=True) and chkbox==False:
print "TtoF"
else:
print "aaaa"
user,pid,db,chkbox} ----我从ajax post request获取这些数据,
userid,project_id,db_profileid,setasdefaultproject(boolean)} -----模型字段
当我尝试检查我的elif条件时,我在控制台" aaaa"(其他部分)中获得输出。 elif怎么了?
答案 0 :(得分:0)
这里的前:
x = 4
if x == 1:
print ("1")
elif (x == 2):
print("2")
elif (x == 3):
print("3")
else:
print("4")