1

I've been working with flask for about a year now and recently started to use blueprints with it. I build a lot of data visualizations web projects with flask and never have had an issue before. Now I do have an issue and the only change is using blueprints.

I get the following error message:

OSError: File b'../project/csv_data/data/Video_Games_Sales.csv' does not exist

my file structure looks like this: [![enter image description here][1]][1]

The routes.py file looks like this:

mod = Blueprint('csv_data', __name__,template_folder='templates', static_folder='static',
                                            static_url_path='/static')
@mod.route('/csv_home')
def homepage():
    return render_template('csv_data/csv_index.html')

@mod.route('/_by_max_rating')
def by_state_shape():
    game_data = pd.read_csv('../project/csv_data/data/Video_Games_Sales.csv')
    print(game_data.head())

The data.py file looks like this: (Please note that if I run data.py I can display the data. It's only when I run the code in the routes.py file where issues arise.)

import csv
from csv import writer
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

class Data():

    def __init__(self):
        self.game_data = pd.read_csv('data/Video_Games_Sales.csv')

    def get_rating_based_year_genre(self):
         print(self.game_data.head())

The init.py looks like this:

from flask import Flask, session, jsonify, redirect, url_for, escape, render_template, request, flash

app = Flask(__name__)

from project.csv_data.routes import mod
from project.site.routes import mod
from project.scraping.routes import mod

app.register_blueprint(site.routes.mod)
app.register_blueprint(csv_data.routes.mod)
app.register_blueprint(scraping.routes.mod)

Everything works fine except when I execute the ajax call and the code hits this line:

game_data = pd.read_csv('../project/csv_data/data/Video_Games_Sales.csv')

I've done similar projects to this in the past with no issue. The only difference is that I'm using blueprints and believe that it has some routing issue that I'm not aware of. Again, calling the csv file in the data.py file works fine. Only when I need to use it in the routes.py file does everything fall apart. Any help on this would be great! Thank you.

ravenUSMC
  • 495
  • 5
  • 23

0 Answers0