在django长时间处理中显示加载gif? [英] show loading gif during long processing in django?
问题描述
此密钥存储在mongoDB数据库中。系统花费3 -4分钟到这个任务。我想在这段时间内显示一些东西[示例:加载图像或等待消息]。
您可以使用块UI 为此目的,它是一个JavaScript库。
替换< input type =submitclass =btn btn-defaultvalue =保存>
with
< button type =buttonclass =btn btn-defaultonclick =submit_form() >保存< /按钮>
使用JavaScript提交表单,并在提交表单时显示您想要显示的图片。您可以观看演示 here 。
I do my project using Django 1.8 . I want put a GIF to during call key_generate
function. How can I do this using Django. I refer this question to reference Link but I couldn't understand how apply it my code.
This is my view function.
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, redirect, render
from django.core.exceptions import PermissionDenied
from django.http import HttpResponse
from django.utils.timezone import now
from django.shortcuts import render_to_response
from .forms import BookmarkForm
from .models import Bookmark
from .forms import KeyGenarateForm
from .models import Key_Gen
from .algo import algo
from pymongo import MongoClient
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
@login_required
def key_create(request):
#print(request.POST)
if request.method == 'POST':
form = KeyGenarateForm(data=request.POST)
expier_date = request.POST['expier_date']
if form.is_valid():
#request.POST._mutable = True
Key_Gen = form.save(commit=False)
Key_Gen.save(expier_date)
return redirect('marcador_bookmark_user',username=request.user.username)
else:
print('form not valied')
else:
form = KeyGenarateForm()
context = {'form': form, 'create_key': True}
return render(request, 'marcador/key_genarate_form.html', context)
This is my form class.
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block title %}
{% if create %}Create{% else %}New Key{% endif %}Serious
{% endblock %}
{% block heading %}
<h2>
Create New Serial Keys
</h2>
{% endblock %}
{% block content %}
{% if create %}
{% url "marcador_key_create" as action_url %}
{% else %}
{% url "marcador_bookmark_search" pk=form.instance.pk as action_url %}
{% endif %}
<form action="{{ action_url }}" method="post" accept-charset="utf-8" >
{{ form|crispy }}
{% csrf_token %}
<p> <b>Expiry Date*:</b> <input type="date" id="datepicker" name="expier_date"></p>
<p><input type="submit" class="btn btn-default" value="Save" ></p>
</form>
{% endblock %}
Further explanation:
I generate 10000 serial keys using this forum.
This keys store in mongoDB database. System spend 3 -4 minutes to this task.I want show some thing [ Example : loading image or wait message ] during this time period.
You can use Block UI for this purpose, it's a JavaScript library.
Replace <input type="submit" class="btn btn-default" value="Save" >
with
<button type="button" class="btn btn-default" onclick="submit_form()">Save</button>
Submit your form with JavaScript and upon submitting form, show image you want to show. You can watch demos here.
这篇关于在django长时间处理中显示加载gif?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!