Need Help With integrating Python Scripts with Django Frame Work

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Need Help With integrating Python Scripts with Django Frame Work

Balu Nanduri
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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Need Help With integrating Python Scripts with Django Frame Work

Larry Martell
Use ajax, e.g.:
https://stackoverflow.com/questions/30456958/python-script-called-by-ajax-executed-by-django-server

On Mon, Apr 16, 2018 at 3:48 PM, Balu Nanduri <[hidden email]> wrote:

> 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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CACwCsY4y2AKtOqBzG0cbzZeD63YrmVHCWorF1eJzd3E7T25y%2Bg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

RE: Need Help With integrating Python Scripts with Django Frame Work

Matthew Pava
In reply to this post by Balu Nanduri

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: [hidden email] [mailto:[hidden email]] 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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/02eb6190ff484840b8729f146bb3e166%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Need Help With integrating Python Scripts with Django Frame Work

jacob duyon
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 <[hidden email]> 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: [hidden email] [mailto:[hidden email]] 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 [hidden email].
To post to this group, send email to [hidden email].
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/02eb6190ff484840b8729f146bb3e166%40ISS1.ISS.LOCAL.

For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CAJsZ3R4qhfS8zHOHFrZkpWeags606hqoVeM-0qgHpbMM6%2BKrGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.