在Django中提交按钮后如何清除表单字段

时间:2018-08-16 10:44:45

标签: python html django

我有这个Views.py

from django.shortcuts import render,redirect
from django.views.generic.edit import FormView
from .forms import ReportForm
from django.views import View
import spacy
import pdb
nlp = spacy.load('en_core_web_sm')


class stopwordsremoval(FormView):
    template_name = 'report.html'
    form_class = ReportForm
    #pdb.set_trace()

    def form_valid(self, form):
        document1 = (form.cleaned_data.get('text'))

        return redirect('report_details', document1)
        return http.HttpResponseRedirect('')

class ReportDetails(View):
    def get(self,request,document1):
        word_lemma = []
        #pdb.set_trace()
        for word in (nlp(document1)):
            a = (word.is_stop, word.text)
            word_lemma.append(a)
        searchedData = (word_lemma)
        return render(request, 'report.html', {'naturallanguageprocessing': searchedData})

forms.py

from django import forms
import pdb

class ReportForm(forms.Form):
     text = forms.CharField(widget=forms.Textarea(attrs={'rows': 5, 'cols': 100}))

它正在创建表单并在html代码下面呈现它

html

  {% extends 'base.html' %}

 {% block content %}
 <h1>StopWordsRemoval</h1>
          <div>
          <form action = "" method = "post" >
               {% csrf_token %}

                  {{ form.as_p}}


          <button type="submit">stopwordsremoval</button>
               </div>



<div >
 <ul>

        <li>{{ naturallanguageprocessing }}</li>

   </ul>
       <a href="{% url 'stopwordsremoval' %}" </a>
       <style>
       div {
            width: 1000px;
            border: 5px solid green;
            padding: 10px;
             margin: 10px;
         }
          </style>
                </div>
                   </div>

    {% endblock %}

我的问题是,当单击按钮形式将显示时,我们可以在同一位置输入输入并获得输出,但是按钮保持相同的形式将不可见。我的要求是,只有当我单击按钮时,所有内容都应该是相同的,它的输出才会显示在下面以及表单应与输入保持不变。

0 个答案:

没有答案