从公式获取输入数据并将其用作函数的参数

时间:2011-03-08 22:57:33

标签: django forms

您好我想知道是否可以从公式获取输入数据并将此数据用于其他函数?

my forms.py:

class TextPathForm(forms.Form):
    text = forms.CharField(required=True)
    language = forms.CharField(required=True)
    stopwords = forms.CharField(required=False)
    search = forms.CharField(required=False)
    filterword = forms.CharField(required=False)

我的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() "):

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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