Django javascript invoke browsers download and save






















Collectives on Stack Overflow. Learn more. Asked 9 years, 6 months ago. Active 9 years, 6 months ago. Viewed 5k times. Using Django, I want to make some data available for download. StringIO jsonFile. For Javascript, I'm not sure what should go into my success handler function. Using django to return an attachment should serve this purpose. Here is an example of returning a csv file to the user. If you want to implement this on a push button, I would actually have a separate view to return this file response.

Then, you can specify in your template to call that view when the button is pushed make sure to link to the view in your urls. It would look something like this:. I actually had a similar issue to this not too long ago - here are a couple of similar questions you can look here , at my question I know it's lame to link to my own question, but I think it may help you , and here too.

Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Next Handling Ajax request in Django.

Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. To implement this, we can do a custom logic. Or a simpler way I could suggest is to utilize third-party library bluebirdjs. The library implemented many helpful promise functions. For this use case, I will use Promise. Notice that Promise here now is the custom Promise provided by the library, not the built-in Promise.

The function returns a Promise, which will resolve when all URLs were downloaded and reject if any of them fail. Now I have everything downloaded into memory. As I mentioned above, the downloaded content is stored as Blob. The next step is to create a zip file using those Blob data. Please follow these coding standards when writing JavaScript code for inclusion in Django. We recommend using a text editor with EditorConfig support to avoid indentation and whitespace issues.

Most of the JavaScript files use 4 spaces for indentation, but there are some exceptions. Different JavaScript files sometimes use a different code style. Please try to conform to the code style of each file.



0コメント

  • 1000 / 1000