1
votes

I am trying to call a function from a python file that is located outside the django project directory from views.py. I have tried importing the python file but running the django server says "no module named xxxx".

Tree structure is given below.


├── auto_flash
│   ├── __init__.py
│   └── test.py
└── fireflash
    ├── detection_reports
    │   ├── admin.py
    │   ├── admin.pyc
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── migrations
    │   │   ├── __init__.py
    │   │   └── __init__.pyc
    │   ├── models.py
    │   ├── models.pyc
    │   ├── __pycache__
    │   │   └── __init__.cpython-35.pyc
    │   ├── templates
    │   │   └── detection_reports
    │   │       └── home.html
    │   ├── tests.py
    │   ├── views.py
    │   └── views.pyc
    ├── fireflash
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── __pycache__
    │   │   ├── __init__.cpython-35.pyc
    │   │   └── settings.cpython-35.pyc
    │   ├── settings.py
    │   ├── settings.pyc
    │   ├── ui_cgi.py
    │   ├── urls.py
    │   ├── urls.pyc
    │   ├── wsgi.py
    │   └── wsgi.pyc
    ├── __init__.py
    └── manage.py  

Project name here is "fireflash" and there is an app in that project named "detection_reports". There is another directory named "auto_flash" that has same location as "fireflash". What I want to do is to import test.py file from "auto_flash" in detection_reports.views and call a function from views. Importing like this "from auto_flash import test" throws error "no module named auto_flash".

2
Can you provide a "file tree" with the relevant files (and their directories)?Willem Van Onsem
A similar question was posted hereAlouani Younes
I have tried the solutions suggested above but none of them worked. Anyone with clean/proper solution.?Asad Ali

2 Answers

0
votes

I have tried all of the above mentioned solutions, but the cleaner solution was to append the path for auto_flash to syspath and the issue was resolved. Thanks to all of you for the efforts.

0
votes
  • Move auto_flash to fireflash
  • In detection_reports add from auto_flash import test.py