2011-03-08 75 views
0

您好,我想知道是否可以从公式中获取输入数据并将该数据用于其他函数?从公式获取输入数据并将其用作函数的参数

我forms.py:

我view.py:

def textpath(request): 
    success = False 
    text = '' 
    stopwords = '' 
    language = '' 
    search = '' 

    if request.method == 'POST': 
     textpath_form = TextPathForm(request.POST) 
     if textpath_form.is_valid(): 
      success = True 
      text = textpath_form.cleaned_data['text'] 
      stopwords = textpath_form.cleaned_data['stopwords'] 
      language = textpath_form.cleaned_data['language'] 
      search = textpath_form.cleaned_data['search'] 

    else: 
     textpath_form = TextPathForm() 

    ctx = {'textpath_form':textpath_form,'text':text,'language':language,'stopwords':stopwords,'search':search,'succes': success,} 

    return render_to_response('index.html',ctx) 

def any_function("need parameter text from textpath() "): 

谢谢你帮助我。

回答

0

你是什么意思?您始终可以将textpath_form.cleaned_data作为参数传递给您的函数,甚至可以通过textpath_form.cleaned_data['text']并在此处执行某些操作。

+0

如果我尝试: def any_function(textpath_form.cleaned_data):我得到一个SyntaxError。 或def any_function(x = textpath_form.cleaned_data): - > NameError text_path未定义 – SnowBallz 2011-03-09 09:23:35

+0

不,不。执行'def any_function(data)',然后像'any_function(textpath_form.cleaned_data)'一样在你的请求中使用它。如果你想存储数据,所以你可以使用'any_function(textpath_form.cleaned_data)'外部请求,那么你需要将它存储在全局变量或数据库中。 – freakish 2011-03-09 12:55:31

+0

啊,现在我明白了。谢谢。 – SnowBallz 2011-03-09 13:47:57

相关问题