我使用Django 1.8做我的项目。我希望在调用key_generate
函数期间输入GIF。我怎么能用Django做到这一点。我将此问题提交给reference Link,但我无法理解如何将其应用于我的代码。
这是我的视图功能。
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)
这是我的表格类。
{% 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 %}
此密钥存储在mongoDB数据库中。系统花费3-4分钟来完成这项任务。我想在这段时间内展示一些东西[例如:加载图片或等待消息]。