问题
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