0

我正在尝试使用“github”上发布的示例链接是http://github.com/tstone/django-uploadify。而且我很难找到工作。你能帮助我吗?我一步一步地跟着,但没有用。

访问“URL”/上传/唯一的就是返回“True”

settings.py 的一部分

import os
PROJECT_ROOT_PATH = os.path.dirname(os.path.abspath(__file__))

MEDIA_ROOT = os.path.join(PROJECT_ROOT_PATH, 'media')
TEMPLATE_DIRS = (  os.path.join(PROJECT_ROOT_PATH, 'templates'))

网址.py

from django.conf.urls.defaults import *
from django.conf import settings
from teste.uploadify.views import *
from django.contrib import admin

admin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),  
    url(r'upload/$', upload, name='uploadify_upload'),
)

视图.py

from django.http import HttpResponse
import django.dispatch

upload_received = django.dispatch.Signal(providing_args=['data'])

def upload(request, *args, **kwargs):
    if request.method == 'POST':
        if request.FILES:
            upload_received.send(sender='uploadify', data=request.FILES['Filedata'])
    return HttpResponse('True') 

模型.py

from django.db import models

def upload_received_handler(sender, data, **kwargs):
    if file:
        new_media = Media.objects.create(
            file = data,
            new_upload = True,
     )

    new_media.save()
    upload_received.connect(upload_received_handler, dispatch_uid='uploadify.media.upload_received')

class Media(models.Model):
    file = models.FileField(upload_to='images/upload/', null=True, blank=True)
    new_upload = models.BooleanField()

uploadify_tags.py

from django import template

from teste import settings 

register = template.Library()

@register.inclusion_tag('uploadify/multi_file_upload.html', takes_context=True)

    def multi_file_upload(context, upload_complete_url):
        """
        * filesUploaded - The total number of files uploaded
        * errors - The total number of errors while uploading
        * allBytesLoaded - The total number of bytes uploaded
        * speed - The average speed of all uploaded files
        """
        return {
            'upload_complete_url' : upload_complete_url,
            'uploadify_path' : settings.UPLOADIFY_PATH, # checar essa linha
            'upload_path' : settings.UPLOADIFY_UPLOAD_PATH,
        }    

模板 - uploadify/multi_file_upload.html

{% load uploadify_tags }{ multi_file_upload '/media/images/upload/' %}
<script type="text/javascript" src="{{ MEDIA_URL }}js/swfobject.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.uploadify.js"></script>
<div id="uploadify" class="multi-file-upload"><input id="fileInput" name="fileInput" type="file" /></div>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
    $('#fileInput').uploadify({
        'uploader'    : '/media/swf/uploadify.swf',
        'script'    : '{% url uploadify_upload %}',
        'cancelImg'   : '/media/images/uploadify-remove.png/',
        'auto'     : true,
        'folder'    : '/media/images/upload/',
        'multi'    : true,
        'onAllComplete' : allComplete
    });
});

function allComplete(event, data) {
 $('#uploadify').load('{{ upload_complete_url }}', {
  'filesUploaded'  : data.filesUploaded,
  'errorCount'   : data.errors,
  'allBytesLoaded'  : data.allBytesLoaded,
  'speed'     : data.speed
 });

 // raise custom event
 $('#uploadify') .trigger('allUploadsComplete', data);
}
// ]]</script>
4

3 回答 3

1

但这正是你告诉它要做的——如果你不发布,那么/upload/视图将简单地返回 True。

我想你想返回一个实际渲染的模板,大概包含{% multi_file_upload %}标签。

于 2010-05-12T18:47:11.590 回答
0

模板上的第 1 行,您的标签没有正确关闭/打开应该是

{% load uploadify_tags %}{% multi_file_upload '/myphotos/my-photos/'%}

话虽如此,我自己也遇到了各种各样的错误……主要是通过 csrf 验证。我看到 tstone 正在免除 csrf,但它仍然认为它应该在那里......但事实并非如此。因此,根据 django 的文档https://docs.djangoproject.com/en/1.3/ref/contrib/csrf/#ajax,我添加了一些东西以使其正常工作。但现在我得到一个 405,因为它正试图发布给它自己。我会继续挖掘并希望找到解决方案。

于 2012-02-28T05:02:38.953 回答
0

您可能会发现以下站点很有用: https ://github.com/tstone/django-uploadify/wiki

于 2011-02-22T18:22:03.963 回答