django+uploadify - 不工作 [英] django+uploadify - don't working

查看:25
本文介绍了django+uploadify - 不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use an example posted on the "github" the link is http://github.com/tstone/django-uploadify. And I'm having trouble getting work. can you help me? I followed step by step, but does not work.

访问URL"/上传/唯一的事情是返回True"

Accessing the "URL" / upload / the only thing is that returns "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'))

urls.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'),
)

views.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') 

models.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>

推荐答案

但这正是你告诉它要做的 - 如果你不发布,那么 /upload/ 视图将只需返回 True.

But that's exactly what you've told it to do - if you're not POSTing, then the /upload/ view will simply return True.

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

I would imagine you want to return an actual rendered template, presumably containing the {% multi_file_upload %} tag.

这篇关于django+uploadify - 不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆