单击提交按钮后,Django表单应保持不变

时间:2018-08-20 11:13:21

标签: python django django-forms

我正在使用django制作停用词删除api。当我提交用户文本输入时,虽然输出相当,但是输出后文本区域不可见。我的要求是在输出以下,但显示输入应该保持不变。

enter image description here enter image description here

下面的代码 正如您在图片快照中看到的那样,文本区域是不可见的。因此它应该是可见的

views.py

   from django.shortcuts import render,redirect,HttpResponse
   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


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

    return redirect('report_details', document1)


            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
class ReportForm(forms.Form):

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

report.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>

   [![enter image description here][1]][1]</ul>
   <a href="{% url 'stopwordsremoval' %}" </a>
        <style>
           div {
                  width: 1000px;
                  border: 5px solid green;
                  padding: 10px;
                  margin: 10px;
                 }
                 </style>
                   </div>
               </div>

            {% endblock %}


      [![this is the user input we are giving][1]][1]






        [1]: https://i.stack.imgur.com/TlSlL.png

    [![this output the text area is not visible have to make visible][1]][1]


  [1]: https://i.stack.imgur.com/M80Un.png

0 个答案:

没有答案