FileTransfers无法下载文件

FileTransfers无法下载文件

本文介绍了使用Django FileTransfers无法下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过网站的管理部分上传文件,希望可以通过我的网站公开下载该文件。我知道我已上传的文件已成功上传,因为我可以在App Engine Blob存储中查看它。我在找出下面的代码无法解决的问题时遇到了麻烦:

I have am uploading a file through the admin section of my site that I would like to be able to be publicly downloaded through my website. I know that the file I have uploaded has been successfully uploaded because I can view it in the App Engine Blob storage. I am having trouble finding out what isn't working with the code below:

modeL的相关部分:

relevant part of my modeL:

class CalendarEvent (models.Model):
    file = models.FileField(upload_to='uploads/%Y/%m/%d/%H/%M/%S/')

在我的views.py文件中,相关代码为:

in my views.py file the relevant code is:

def calendar(request):
    events = CalendarEvent.objects.exclude(start__lt=datetime.datetime.now()).order_by('start')
    return render_to_response('home/calendar.html',{'events': events},context_instance=RequestContext(request))

def download_handler(request, pk):
    upload = get_object_or_404(CalendarEvent, pk=pk)
    return serve_file(request, upload.file, save_as=True)

在我的模板中,相关代码为:

in my template the relevant code is:

{% for e in events %}
    {% url Calendar.views.download_handler pk=e.pk as fallback_url %}
    <a href="{% firstof e.file|public_download_url fallback_url %}">Download</a>
{% endfor %}


推荐答案

您的视图您的download_handler的名称应为< appname> .views.download_handler 。您可能没有名为 e的应用,且其中包含适当的视图。

Your view name for your download_handler should be <appname>.views.download_handler. You probably don't have an app named "e" with an appropriate view in it.

这篇关于使用Django FileTransfers无法下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 04:44