1

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".

4
  • 1
    Can you provide a "file tree" with the relevant files (and their directories)? Commented Dec 24, 2018 at 19:01
  • 2
    Possible duplicate of How import a function from another view with Django? Commented Dec 24, 2018 at 19:17
  • A similar question was posted here Commented Dec 24, 2018 at 23:45
  • I have tried the solutions suggested above but none of them worked. Anyone with clean/proper solution.? Commented Dec 25, 2018 at 11:58

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.