0

I have a flask app which will read some dataframes and displays some output in front end. I have two routes. One will accept user input and is send to second route. Second route make use of this input and process some dataframe and provides some output. Issue is, if go to user input page again and if I try submitting another input, it gives me page not working error. Is it because of any memory issue? If I restart my sever, then I repeat it once(every time I need to restart).

from flask import flash, redirect, render_template, url_for, request, jsonify
import math
import os
import glob
import pandas as pd
from . import fa
from database import connection
UPLOAD_DIRECTORY = './uploads'
if not os.path.exists(UPLOAD_DIRECTORY):
    os.makedirs(UPLOAD_DIRECTORY)

@fa.route('/fc', methods=['GET', 'POST'])
def index():
    return render_template('fc.html',flag=0)

@fa.route('/fc/s', methods=['GET', 'POST'])
def start():
    if request.method == 'POST':
            material_number = request.form['ma']
            path = UPLOAD_DIRECTORY
            extension = 'xlsx'
            os.chdir(path)
            result = [i for i in glob.glob('*.{}'.format(extension))]
            allFiles = result
            frame = pd.DataFrame()
            list_ = []
            for file_ in allFiles:
                df = pd.read_excel(file_)
                list_.append(df)
            frame = pd.concat(list_)
            frame = frame.reset_index(drop=True)
            df1 = frame[frame['Ma'].str.contains(ma,regex=True)]
            pr = df1['Pr'].unique().tolist() 
            pro = pd.read_excel(r'~pathhiddn~\dtrvsproj.xlsx')
            return render_template('fc.html',flag=1,ma=ma,prs=pr)
    return redirect(url_for('fa.index'))
qwww
  • 1,313
  • 4
  • 22
  • 48
  • Debug your code, check in which line, it stops working, like put the print statement before/after you do something with dataframe, and also before return, and be sure where it's stuck. – user2906838 Jul 30 '18 at 10:43
  • Can we see what the error is in your logs? – Tim Thompson Jul 30 '18 at 10:45
  • what i understood is the for loop part is having issue..until that it works well – qwww Jul 30 '18 at 10:50
  • when I removed all code from : `path = UPLOAD_DIRECTORY` to `pro = pd.read_excel(r'~pathhiddn~\dtrvsproj.xlsx')` it is working fine – qwww Jul 30 '18 at 11:11
  • `df = pd.read_excel(file_) list_.append(df)` these lines are causing issue..... – qwww Jul 30 '18 at 11:43

1 Answers1

0
os.chdir(path)

This was causing the issue. I removed that and replaced df = pd.read_excel(file_) with df = pd.read_excel('./uploads/data/'+file_)

qwww
  • 1,313
  • 4
  • 22
  • 48