Forums

Issue importing Additional Files to Main Python File

I am attempting to create a flask app that relies on a number of functions that are defined in several other files. In my main file that contains all the flask routes and corresponding functions I tried importing my files. However, I keep receiving an error: ImportError: No module named db_interaction and ImportError: No module named college_majors.

Here is the file hierarchy:

  templates/
  css/
  addons/
      college_majors.py
      db_interaction.py
      __init__.py
  scholarscout.py

Inside scholarscout.py, I am importing the files like so:

import addons.db_interaction as db_interaction
import addons.college_majors as college_majors
import flask


app = flask.Flask(__name__)

Can anyone tell me how to resolve this error?

Are you sure you're looking at the right errors in the error log? The last one I can see in your logs relates to a different package. Remember that the most recent error is at the bottom of the logfile.

Thank you very much! I was looking at the wrong error message. The app has successfully deployed!

Excellent -- glad to help!