开发者

Getting Input Data from a formular and use it as a parameter for a function

Hello I wanted to know if it possible to get input-data from a formular and use this data for another function?

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)

my 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 =开发者_Go百科 {'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() "):

Thanks for helping me.


What do you mean? You can always pass textpath_form.cleaned_data to your function as an argument or even pass textpath_form.cleaned_data['text'] and do something with it there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜