Trouble downloading file using Django FileTransfers

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 03:01:15

问题


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:

relevant part of my modeL:

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

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 %}

回答1:


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.



来源:https://stackoverflow.com/questions/13187401/trouble-downloading-file-using-django-filetransfers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!