0👍
✅
urls.py
url(r'^handles3downloads/', handles3downloads),
views.py
def handles3downloads(request):
fname = request.GET['filename']
bucket_name = 'bucketname'
key = s.get_bucket(bucket_name).get_key(fname)
key.get_contents_to_filename('/tmp/'+key.name)
wrapper = FileWrapper(open('/tmp/'+fname, 'rb'))
content_type = mimetypes.guess_type('/tmp/'+fname)[0]
response = HttpResponse(wrapper,content_type=content_type)
response['Content-Length'] = os.path.getsize('/tmp/'+fname)
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(fname)
templates
<a href="/handles3downloads/?filename=file1.jpg" rel="external">Download</a>
👤Niya
2👍
Your regular expression in the urls.py
file seems to be wrong. Try using this instead:
url(r'^handles3downloads/(\w+)/$', handles3downloads),
You’re passing parameter string to the view, and the regex
is matching integers.
- [Answered ]-Django Message Application duplication error
- [Answered ]-RemovedInDjango19Warning – isn't in an application in INSTALLED_APPS
- [Answered ]-Django cache, weather site auto-refresh cache every 5 minutes
- [Answered ]-Apache hangs with Django / Matplotlib app
- [Answered ]-SELECT using psql returns no rows even though data is there
0👍
Jordan is correct, there is a problem with your urls.py. You can tell by the error. You are trying to get a reverse on ‘myapp.views.handles3downloads’, but has that reverse string been identified? Try this.
urlpatterns = patterns('',
url(r'^handles3downloads/([^/]+)/$', handles3downloads,
name='myapp.views.handles3downloads'),
)
- [Answered ]-Django – Make private page by user
- [Answered ]-How to allow for complex URLs on a Django-rest-framework viewset
- [Answered ]-Django Relationship Name Collisions – Abstract Model has multiple relationships with another Model
- [Answered ]-Load content from Ajax-loaded content
Source:stackexchange.com