python - Django : NameError at /approved/filter/7/ - name 'testElement' is not defined -
i new django , trying send different context variable depending on if statement satisfied. view:
class filtersearch(view): template_name = 'approved/approvedelementsseview.html' def post(self,request,testplanid): elemtype = request.post.get('testelementtype'); elemcategory = request.post.get('category'); if(elemcategory=='routing'): global testelement; testelement=approvedtestelement.objects.filter(testelementtype=elemtype, routing='y'); return testelement elif(elemcategory=='switching'): global testelement; testelement = approvedtestelement.objects.filter(testelementtype=elemtype, switching='y'); return testelement return render(request,self.template_name,{'testelement':testelement,'testplanid':testplanid})
i getting unboundlocalerror:local variable 'testelement' referenced before assignment , tried fixing defining testelement global variable, getting nameerror: name 'testelement' not defined. appreciated!
class filtersearch(view): template_name = 'approved/approvedelementsseview.html'
def post(self,request,testplanid): elemtype = request.post.get('testelementtype'); elemcategory = request.post.get('category'); if(elemcategory=='routing'): testelement = approvedtestelement.objects.filter(testelementtype=elemtype, routing='y'); if(elemcategory=='switching'): testelement = approvedtestelement.objects.filter(testelementtype=elemtype, switching='y'); return render(request,self.template_name,{'testelement':testelement,'testplanid':testplanid})
Comments
Post a Comment