python - Django importing another file from another package -


i have following folder structure

 app/ app/helpers/ app/helpers/methodhelper.py app/methods/ app/methods/method.py 

and i'm trying import function methodhelper.py inside method.py
tried following:

 import app.helpers.methodhelper or app.helpers.methodhelper import function1 or import helpers.methodhelper 

and get:

"no module named app.helpers.methodhelper"  

important note: helpers/__init__.py exists

how should done ?

your django project's default path in root directory of project (where manage.py file is). can either add sub directories below pythonpath (easily done appending sys.path) or can import function using full module path:

from projectname.app.helpers.methodhelper import function1

when start django project, add

project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

to settings.py. path looks similar /home/kyle/django_project_name/. inside directly manage.py.

from there, in settings.py, include:

sys.path.append(os.path.join(project_root, 'django_project_name'))

this makes apps importable without need include project name in module path.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -