1

I am new to python and django and was trying to make a basic webapp and while doing that, i wanted to add some helper functions in a separate folder inside my app folder.

The structure is :

  • app
    • utils
      • testFile.py
    • migrations
    • static
    • urls.py
    • views.py
    • ....
    • ....

My testFile.py has one function for now

    def testFunc():
        print("IT WORKS")

I am calling it my views.py

    from testFile import testFunc

and tried the following too

    from utils.testFile import testFunc

but none of them worked.

After that I checked for directories in which python is looking into using sys.path, and utils wasn't there, so I added it using sys.path.insert(), but that doesn't work too.

It keeps giving the no module named testFile error

I tried creating two simple python files and calling function of one from the other, it works there. So only while I am using in my django webapp, the error is coming. What am I doing wrong here?

1 Answers1

1

Try this:

from .utils.testFile import testFunc

Or pass the complete path:

from app.utils.testFile import testFunc
fgalvao
  • 460
  • 6
  • 18