Django: Modifying excel data and downloading a ppt

I am currently facing an issue with deployement:

I so far created an app where I am inputing a local path to an excel file than using the sample_code.py (shown bellow) I create a report in pptx in the same folder where the excel file is.

To Summarize:

  • I input text into a form the text is my path to the excel file
  • I click a button that runs my sample_code.py script
  • A ppt report is generated

Why does this not work when deploying on heroku, and how could I improve it?

EDIT: my idea was to upload a static file to some media/excel_files folder and create a pptx in a media/pptx_files folder. the issue is I'm not sure how to specify this path inmy sample_code.py script. Than download the pptx.

My views.py files are as follows:

from django.shortcuts import render
import sys
from subprocess import run, PIPE

# Create your views here.
def button(request):
    return render(request,'home.html')

def external(request):
    inp=request.POST.get('param')
    out=run([sys.executable,'E:\\project_deployement\\sample_code.py',inp],shell=False,stdout=PIPE)
    print(out)
    return render(request,'home.html',{'data1':out.stdout.decode('utf-8')})

the urls.py

from django.urls import path
from . import views

urlpatterns = [
        path('', views.button),
        path('external/', views.external),
]

and the home.html file is as follows

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Work Script</title>
  </head>
  <body>
    <form action="/external/" method="post">
      {% csrf_token %}
      Input Path:
      <input type="text" name="param" required><br><br>
      {{ data_external }}
      <input type="submit" value="Generate Toplines">
    </form>
  </body>
</html>

the last important step is the sample_code.py

from pptx import Presentation
from pptx.chart.data import CategoryChartData
from pptx.enum.chart import XL_CHART_TYPE
from pptx.util import Inches
import pandas as pd
import sys


path = "%s" % (sys.argv[1])

pr1 = Presentation()

slide2_reg = pr1.slide_layouts[0]

slide2 = pr1.slides.add_slide(slide2_reg)

title2 = slide2.shapes.title
title2.text = "slide 1"

slide1_reg = pr1.slide_layouts[5]

slide1 = pr1.slides.add_slide(slide1_reg)

title1 = slide1.shapes.title
title1.text = "slide 2"

df = pd.read_excel (path+'sample_data.xlsx')
df = df.groupby('Product')['variable_x'].mean()

chart_data = CategoryChartData()
chart_data.categories = list(df.index)[0], list(df.index)[1] #gets string categories
chart_data.add_series('variable_x', (df.iat[0], df.iat[1])) #gets integer values

x, y, cx, cy = Inches(1), Inches(1), Inches(2), Inches(2.5)
slide1.shapes.add_chart(
    XL_CHART_TYPE.COLUMN_CLUSTERED, x, y, cx, cy, chart_data
)

pr1.save(path+'presentation.pptx')
Back to Top