Example of a URL wildcard:
URL (r'^file_download/(? P<filename> (.) *) $', Views. File_download_view.as_view ()),
Code example:
DefGet(self, request, filename): fromcommon.s3_storage Import s3_storage s3_storage=s3_storage () Key=S3_storage.package_bucket.get_key (filename) assert (key isnot None) Import Tempfile temp=Tempfile. Namedtemporaryfile ()Try: #temp=Tempfile. Temporaryfile () key.get_contents_to_filename (temp.name) Temp.seek (0) C=temp.read () #c=key.get_contents_as_string () #returnApiresponse (status=status_code.success, Data=Os_and_kernel_maps) fromdjango.http Import streaminghttpresponse #response=HttpResponse (c) Response=streaminghttpresponse (c) #response=streaminghttpresponse (self.file_iterator (temp)) response['Content-type'] ='Application/octet-stream'Import OS response['Content-length'] =os.path.getsize (temp.name) response['content-disposition'] ='attachment;filename= "{0}"'. Format (filename)returnResponsefinally: Temp.close ()
"Python" Django supports restful style URLs