python - 如何在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})
表格.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 %}
我的问题是,当单击按钮表单将显示时,我们可以在同一位置输入输入并获取输出,但按钮保持相同的表单将不可见。我的要求是一切都应该只有当我单击按钮时,它的输出才会显示在下面,并且表单应该保持不变与输入相同。
解决方案
推荐阅读
- python - 如何在 Django 中从 views.py 中导入变量?
- google-my-business-api - 任何 GMB 位置的问答部分是否有任何预览 URL...?
- spring-boot - Java Spring Boot:使独立应用程序无需退出即可运行
- php - 如何只显示一次结果检查的消息
- java - 春季启动:java.lang.NoSuchMethodError:javax.servlet.http.HttpServletRequest.getHttpServletMapping()Ljavax/servlet/http/HttpServletMapping;
- json - json中特定变量后的jinja匹配字符串
- android - [Android][RecyclerView] 行可见时回调
- javascript - 使用多个相同的下拉列表 ID,但第二个下拉列表不会触发 onchange 事件
- vue.js - vue ref($refs) 在挂载的 nextTick 中未定义
- laravel-5 - 如何修复资源路由定义的错误