如何在django中将值从一个方法传递给另一个方法

时间:2014-04-23 05:56:00

标签: django

views.py 这是视图中的方法,我想将pass_viewerProjFeature中的project_id,feature_name值传递给sortbyName

def passReviewerProjFeature(request):

                testcase_object_array=""

                if request.method == 'POST':
                    reviewer_name = request.POST['reviewer_id']
                    project_id = request.POST['tcrproject_id']
                    feature_name = request.POST['tcrsearch_id']
                    id=FeatureCache.objects.filter(name=feature_name)
          testcase_object_array=TestcaseCache.objects.filter(project=project_id).filter(feature=id)

                return render(request,'tcrform.html',{'form':TestcaseCacheForm(),'testcase_object_array':testcase_object_array})

这里的sortbyName方法我想要从html页面获取的值assReviewerProjFeature

def sortbyName(request):

这里我想要来自passReviewerProjFeature方法的函数中的project_id,feature_name变量值

1 个答案:

答案 0 :(得分:0)

试试这种方式,

def sortbyName(request, project_id, feature_name):
     do your logic here
     pass

def passReviewerProjFeature(request):

      testcase_object_array=""

      if request.method == 'POST':
            reviewer_name = request.POST['reviewer_id']
            project_id = request.POST['tcrproject_id']
            feature_name = request.POST['tcrsearch_id']
            id=FeatureCache.objects.filter(name=feature_name)

            testcase_object_array=TestcaseCache.objects.filter(project=project_id).filter(feature=id)
            sortbyName(request, project_id, feature_name) --> My Edit

      return render(request,'tcrform.html',{'form':TestcaseCacheForm(),'testcase_object_array':testcase_object_array})