"Python" Django supports restful style URLs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.