Need Help With integrating Python Scripts with Django Frame Work

14 views
Skip to first unread message

Balu Nanduri

unread,
Apr 16, 2018, 4:01:09 PM4/16/18
to Django users
Hi,
         I am working on a project where I have to communicate with Tableau server and generate pptx with the images downloaded. I have a working script to do this piece, currently the script generates pptx and stores it to my local filesystem.

Now I would like to create a web page which would accept necessary input from users and should trigger the script which generates pptx and then downloads the files to the user's browser.

I had set up DJANGO environment of the same but not getting how to call this script from the web page so, could anyone help me out with a overview on how can I call my working script on click of a button and download the files generated by the script.

Thanks & Regards
Balu

Larry Martell

unread,
Apr 16, 2018, 4:07:55 PM4/16/18
to django...@googlegroups.com

Matthew Pava

unread,
Apr 16, 2018, 4:07:55 PM4/16/18
to django...@googlegroups.com

Add a new view that returns the files.  Connect the “Download” button to the URL to that view.

Your view should return an HttpResponse object.  For instance, I use this for the user to download PDF versions of forms:

 

response = HttpResponse(pdf_contents, content_type='application/pdf')
response[
'Content-Disposition'] = "%sfilename=%s" % ('attachment; ' if download else '', filename)
return response

 

For pptx, your content_type would be:

'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b5471890-0cd8-4ee7-a7c5-c43840590a4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

jacob duyon

unread,
Apr 16, 2018, 4:18:57 PM4/16/18
to django...@googlegroups.com
I'm not sure how many users you have for this, but it's best practice to use an asynchronous task queue (like Celery) to run the actual powerpoint creation code. If you simply run the script inside the view it will block the response from happening. You create a celery task (which in your case would have the powerpoint code), and the view will add the task to the queue. 

Celery requires a message broker, like RabbitMQ or Redis in order to use it. They are both simple to setup and work well. The docs are pretty good too.

On Mon, Apr 16, 2018 at 4:06 PM, Matthew Pava <Matthe...@iss.com> wrote:

Add a new view that returns the files.  Connect the “Download” button to the URL to that view.

Your view should return an HttpResponse object.  For instance, I use this for the user to download PDF versions of forms:

 

response = HttpResponse(pdf_contents, content_type='application/pdf')
response[
'Content-Disposition'] = "%sfilename=%s" % ('attachment; ' if download else '', filename)
return response

 

For pptx, your content_type would be:

'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',

 

 

From: django...@googlegroups.com [mailto:django-users@googlegroups.com] On Behalf Of Balu Nanduri
Sent: Monday, April 16, 2018 2:48 PM
To: Django users
Subject: Need Help With integrating Python Scripts with Django Frame Work

 

Hi,

         I am working on a project where I have to communicate with Tableau server and generate pptx with the images downloaded. I have a working script to do this piece, currently the script generates pptx and stores it to my local filesystem.

 

Now I would like to create a web page which would accept necessary input from users and should trigger the script which generates pptx and then downloads the files to the user's browser.

 

I had set up DJANGO environment of the same but not getting how to call this script from the web page so, could anyone help me out with a overview on how can I call my working script on click of a button and download the files generated by the script.

 

Thanks & Regards

Balu

--
You received this message because you are subscribed to the Google Groups "Django users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages