Forums

Trouble configuring the modules of my Flask app

I have a web app I'm trying to get running, I have uploaded the files and followed the steps on the setting up page but still no luck

I'm currently getting the error : IOError: [Errno 2] No such file or directory: 'json-key.json'

flask_app.py

from __future__ import division
import datetime
import settings
from flask import Flask
from flask import request
from flask import render_template 
import mpld3
import numpy as np
import matplotlib.pyplot as plt

app = Flask(__name__)

@app.route('/')
def my_form():
    return render_template("template.html")

@app.route('/', methods=['POST', 'GET'])
def my_form_post():
    requestParams = []
    location = request.form.get('location','')
    requestParams.append(location)
    #sType = request.form.get('sType', '')
    #requestParams.append(sType)
    day = request.form.get('day','')
    requestParams.append(day)

    # from myapp import requestParams

    hour = []
    daysAvs = []

    carParkData = (settings.db.child("Car Parks").child(requestParams[0] + " (LUL)").child("Pay and Display 
Parking").child(
            requestParams[1]).get().val())

    for i in carParkData:
        for key, value in i.iteritems():
            hour.append(value)
        hAv = sum(hour) / len(hour)
        daysAvs.append(int(hAv))
        print daysAvs
        hour[:] = []

    colours = []

maxCap = max(daysAvs)

for i in daysAvs:
    p = float((i / maxCap) * 100)
    if p > 90:
        colours.append('#EE7785')
    elif p < 90 and p > 60:
        colours.append('#D68975')
    elif p < 60 and p > 30:
        colours.append('#FCD0A1')
    elif p < 30 and p > 10:
        colours.append("#67D5B5")
    elif p < 10 and p > 5:
        colours.append('#67D5B5')

N = 24

ind = np.arange(N)  # the x locations for the groups
width = 1  # the width of the bars

fig, ax = plt.subplots()
rects = ax.bar(ind, daysAvs, width, color=colours)

# add some text for labels, title and axes ticks
ax.set_ylabel('Empty Car Park Spaces')
ax.set_xlabel('Hour of the Day')
ax.set_title('Average Car park use of ' + requestParams[0] + ' on ' + requestParams[1])
plt.tick_params(
    axis='x',
    which='both',
    bottom='on',
    top='off',
    labelbottom='on')
plt.axis('tight')

times = []

for i in range(10):
    times.append('0' + str(i) + ':00')

for i in range(10, 24):
    times.append(str(i) + ':00')

# plt.text(0.0, -2.0, '00:00', rotation=-45)
# axis label example
chart = mpld3.fig_to_html(fig)

return render_template("template.html", chart=chart)

if __name__ == '__main__':
    app.debug = True
    app.run()

settings.py

import pyrebase


config = {
  "apiKey": "AIzaSyCskK7CtSYkAMEZxckL9mVSDOuYPOgH95g",
  "authDomain": "car-parks.firebaseapp.com",
  "databaseURL": "https://car-parks.firebaseio.com",
  "storageBucket": "car-parks.appspot.com",
  "serviceAccount": "json-key.json"
}
firebase = pyrebase.initialize_app(config)

auth = firebase.auth()
user = auth.sign_in_with_email_and_password("h@difol.co", "Canipark676here")
db = firebase.database()

03difoha_pythonanywhere_com_wsgi.py

import sys
path = '/home/03difoha/mysite'
if path not in sys.path:
    sys.path.append(path)
from flask_app import app as application

folder structure: 03difoha/ mysite/ flask_app.py settings.py templates/ template.html

Ok so I have located the JSON key file that was missing.

Getting a new error now: ImportError: No module named mpld3

I have installed mpld3 using pip install in the virtualenv

I have tried pip install --user mpld3 but I get the error : Can not perform a '--user' install. User site-packages are not visible in this virtualenv.

I just took a look at your web site, and it doesn't seem to be using a virtualenv...? You need to enter the path to the virtualenv (or just its name if you're using mkvirtualenv to create it) on the "Web" tab.