python - 当文件准备好时,在 Django 中的 UI 上显示字符串
问题描述
接下来我想做
当按下提交按钮时,Django会生成一些文件(这需要一些时间,大约一分钟)我希望提交按钮旁边会出现另一个按钮,以便在生成完成后(本地)下载这个文件。
屏幕截图: 图像
HTML:
{% load bootstrap %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>Create SWM Client Environment</title>
</head>
<body>
<nav class="navbar navbar-dark bg-dark">
<h4 style="color: aliceblue;">Create SWM client environment</h4>
</nav>
<div style="padding: 20px;">
<form method="post">
{% csrf_token %}
<div class="form-group container w-25">
{{ form|bootstrap }}
</div>
<div class="container w-25">
<button type="reset" class="btn btn-primary">Reset</button>
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</body>
</html>
形式:
class ContactForm(forms.Form):
swm_server = forms.CharField(
label='server',
widget=forms.TextInput(attrs={'placeholder': 'Server IP or Server DNS'}))
def clean(self):
cleaned_data = super(ContactForm, self).clean()
swm_server = cleaned_data.get('swm_server')
意见:
def home(request):
if request.method == 'POST':
form = ContactForm(request.POST)
if form.is_valid():
pass # does nothing, just trigger the validation
else:
form = ContactForm()
return render(request, 'home.html', {'form': form})
解决方案
推荐阅读
- sitecore - 通过构建配置更改 TDS 项目部署
- angular - Using async await firebase storage
- database - Query Most Recent Records in MS Access Based on Date Provided in Form Field
- r - How do I split a table into several new tables based on whether the column header matches with information found in another table? (R)
- android - Android:无法在 NavigationView 的共享类中设置 onCreateOptionsMenu 和 onOptionsItemSelected
- excel - 删除单元格值时崩溃 Worksheet_Change 事件
- nunit - 是否可以将测试参数排除在 NUnit 3 测试结果 XML 中?
- r - Save a list of plots dynamically
- sql - 在 LISTAGG 选项方面需要一些帮助
- tensorflow - 如何让 TensorFlow XLA 知道 CUDA 路径