我正在尝试使用此模块'django-progressbarupload'(https://github.com/ouhouhsami/django-progressbarupload)。我已经按照github页面到Letter的安装说明进行操作,但无法在Chrome或Firefox中获得上传栏。
设置settings.py文件的说明非常简单,我设置了我的admin.py:
## For the Model Admins for the File Upload classes ( Video and Audio )
from django.contrib import admin
## Get the forms
from django import forms
## Import the file models
from models import VideoFile
from models import AudioFile
## For the progress bar
class UploadAudioFileModelForm(forms.ModelForm):
class Meta:
model = AudioFile
class UploadVideoFileModelForm(forms.ModelForm):
class Meta:
model = VideoFile
## For the progress bar
class UploadAudioFileModelAdmin(admin.ModelAdmin):
change_form_template = 'progressbarupload/change_form.html'
add_form_template = 'progressbarupload/change_form.html'
form = UploadAudioFileModelForm
class Media:
js = ("http://code.jquery.com/jquery.min.js",)
## For the progress bar
class UploadVideoFileModelAdmin(admin.ModelAdmin):
change_form_template = 'progressbarupload/change_form.html'
add_form_template = 'progressbarupload/change_form.html'
form = UploadAudioFileModelForm
class Media:
js = ("http://code.jquery.com/jquery.min.js",)
admin.site.register(VideoFile, UploadVideoFileModelAdmin)
admin.site.register(AudioFile, UploadAudioFileModelAdmin)
这是我的上传模板:
{% extends "base.html" %}
{% load progress_bar %}
{% block title %}Upload your !{% endblock %}
{% block content %}
<h1>Upload Information -</h1>
{% if form.errors %}
<p class="error">
Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %}
<script type="text/javascript" src="../media/js/jquery.formset.js"></script>
<script type="text/javascript">
$(function() {
$('#upload_formset ul').formset({
addText: 'Add a new Stop',
deleteText: 'Remove this Stop'
});
})
</script>
<script type="text/javascript" src="../media/js/progress_bar.js"></script>
<form id="upload_formset" action="" method="POST" enctype="multipart/form-data"> {% csrf_token %}
<table>
{{ form.as_table }}
</table>
<br><br/>
<table>
{{ formset.management_form }}
{% for forms in formset.forms %}
<ul>
{{ forms.as_p }}
</ul>
{% endfor %}
</table>
<br><br/>
{% progress_bar %}
<input type="submit" value="Submit!">
</form>
{% endblock %}
这是我的base.html:
{% load static %}
{% load progress_bar %}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="{% static "css/base_style.css" %}">
<title>{% block title %}Welcome!{% endblock %}</title>
{% block additional_head_info %}{% endblock %}
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
</head>
<body>
<h1>Welcome to the Website!</h1>
{% if not user.is_authenticated %}
<a href="/accounts/login/?next=/">login</a> | <a href="/accounts/register/">register</a> | <a href="/">home</a>
{% endif %}
{% if user.is_authenticated %}
<a href="/accounts/logout/?next=/">logout</a> | <a href="/">home</a> | <a href="/upload/">upload</a>
{% endif %}
{% block content_title %}{% endblock %}
{% block content %}{% endblock %}
{% block footer %}
<hr>
<img src="{% static "img/debian-logo.png" %}" alt="Tours Logo"/>
<p>Thanks for visiting - more content coming soon....</p>
{% endblock %}
</body>
</html>
以下是Django渲染后我的网页的来源:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="/static/css/base_style.css">
<title>Upload your !</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
</head>
<body>
<h1>Welcome to the '' Website!</h1>
<a href="/accounts/logout/?next=/">logout</a> | <a href="/">home</a> | <a href="/upload/">upload</a>
<h1>Upload Information -</h1>
<script type="text/javascript" src="../media/js/jquery.formset.js"></script>
<script type="text/javascript">
$(function() {
$('#upload_formset ul').formset({
addText: 'Add a new Stop',
deleteText: 'Remove this Stop'
});
})
</script>
<script type="text/javascript" src="../media/js/progress_bar.js"></script>
<form id="upload_formset" action="" method="POST" enctype="multipart/form-data"> <input type='hidden' name='csrfmiddlewaretoken' value='O6NmPrifvScHP9IUXJIdaf0wnlrGFQgU' />
<table>
<tr><th><label for="id_name"> Name:</label></th><td><input id="id_name" maxlength="100" name="name" type="text" /><br /><span class="helptext">My Awesome </span></td></tr>
<tr><th><label for="id_contact_email">Contact Email:</label></th><td><input id="id_contact_email" name="contact_email" type="text" /><br /><span class="helptext">John.Appleseed@gmail.com</span></td></tr>
<tr><th><label for="id_description"> Description:</label></th><td><textarea cols="40" id="id_description" name="description" rows="10">
</textarea></td></tr>
<tr><th><label for="id_website">Website:</label></th><td><textarea cols="40" id="id_website" name="website" rows="1">
</textarea><br /><span class="helptext">e.g. http://www.ptrackapp.com</span></td></tr>
<tr><th><label for="id_address">Address:</label></th><td><textarea cols="40" id="id_address" name="address" rows="1">
</textarea><br /><span class="helptext">e.g. 1234 Colorado Ave. Denver, Colorado 80201</span></td></tr>
</table>
<br><br/>
<table>
<input id="id_form-TOTAL_FORMS" name="form-TOTAL_FORMS" type="hidden" value="2" /><input id="id_form-INITIAL_FORMS" name="form-INITIAL_FORMS" type="hidden" value="0" /><input id="id_form-MAX_NUM_FORMS" name="form-MAX_NUM_FORMS" type="hidden" value="1000" />
<ul>
<p><label for="id_form-0-address"> Step:</label> <textarea cols="40" id="id_form-0-address" name="form-0-address" rows="1">
</textarea> <span class="helptext">Enter an Address for this Stop</span></p>
<p><label for="id_form-0-description"> Step Description:</label> <input id="id_form-0-description" maxlength="250" name="form-0-description" type="text" /> <span class="helptext">Enter some Information about this Stop</span></p>
<p><label for="id_form-0-video"> Step Video File:</label> <input id="id_form-0-video" name="form-0-video" type="file" /> <span class="helptext">max. 42 megabytes</span></p>
<p><label for="id_form-0-audio"> Step Audio File:</label> <input id="id_form-0-audio" name="form-0-audio" type="file" /> <span class="helptext">max. 42 megabytes</span></p>
</ul>
<ul>
<p><label for="id_form-1-address"> Step:</label> <textarea cols="40" id="id_form-1-address" name="form-1-address" rows="1">
</textarea> <span class="helptext">Enter an Address for this Stop</span></p>
<p><label for="id_form-1-description"> Step Description:</label> <input id="id_form-1-description" maxlength="250" name="form-1-description" type="text" /> <span class="helptext">Enter some Information about this Stop</span></p>
<p><label for="id_form-1-video"> Step Video File:</label> <input id="id_form-1-video" name="form-1-video" type="file" /> <span class="helptext">max. 42 megabytes</span></p>
<p><label for="id_form-1-audio"> Step Audio File:</label> <input id="id_form-1-audio" name="form-1-audio" type="file" /> <span class="helptext">max. 42 megabytes</span></p>
</ul>
</table>
<br><br/>
<progress id="progressBar" data-progress_bar_uuid="131a107d-49ac-4e30-b307-5097dd13e232" value="0" max="100" hidden></progress><script>upload_progress_url = "/progressbarupload/upload_progress"</script>
<input type="submit" value="Submit!">
</form>
<hr>
<img src="/static/img/debian-logo.png" alt=" Logo"/>
<p>Thanks for visiting - more content coming soon....</p>
</body>
</html>
页面加载,我可以上传我的文件,但我从来没有看到进度条。我也没有在FireBug中看到任何加载任何脚本的错误......任何想法?谢谢!
答案 0 :(得分:1)
django-progressbarupload存在某种“问题”,请点击此处https://github.com/ouhouhsami/django-progressbarupload/issues/2。如果您使用Chrome,则进度会显示在Chrome上传栏中(请在屏幕左下方查看)。