Django return a downloadable file but also render






















Active 1 month ago. Viewed 36k times. ODFTemplate 'test. How do I make it start downloading as file instead? Improve this question. Viktor Viktor 3, 3 3 gold badges 32 32 silver badges 57 57 bronze badges. You mean to say that you have created an word file which you need to pass to Front End so that Front end user should able to download it? Wanare exactly — Viktor.

Maybe after the file is generated, if it's publicly accessible from your web server without Django code, authorisation, etc you could send a Redirect response.

Add a comment. Active Oldest Votes. The trick is to use a custom renderer so you can return a Response directly from the view: from django. BaseRenderer : """ Return data as-is. View should supply a Response. Improve this answer. Jack Cushman Jack Cushman 1, 20 20 silver badges 13 13 bronze badges.

Community Bot 1 1 1 silver badge. Piyush S. Wanare Piyush S. Wanare 3, 3 3 gold badges 32 32 silver badges 47 47 bronze badges. I don't get this line yourFilePointer. My file is already generated and saved on server. What text should I write there? Text will be the your word file text.

Here the first function index is used to render the starting page where, the user will fill the forms. Second function index2 is used to submit the form created in the index html page to our model upload.

After saving the model we are going to call all the objects from the model and render to the index2 html page. HTML :- Here in this file we had created a form with method equals to post and specify the action or the URL to relocate after the user clicks on the submit button. HTML:- Here, this file is loaded when the user clicks the submit button in the index. Here we passed all the objects of our model which specifies the title and URL of the uploaded file.

If you focus on the anchor tag, I had passed the URL of the file in HREF and specified the keyword download inside it, so that when the user clicks the link instead of redirecting to a new page, it will download the file. I hope this blog will be useful for you and helps you to understand each and every step. Please help us improve Stack Overflow.

Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 8 years, 1 month ago. Active 2 years, 3 months ago. Viewed 15k times. ZipFile 'foo. ZipInfo 'helloworld. StringIO 'helloworld'.

Improve this question. Paulo Bu Why are you rendering a template which is a. Are you sure that's what's in the doc for serving files? Are you sure render is the proper word of what you want? I rather think you just want to serve it for people to download it am I right?



0コメント

  • 1000 / 1000