简体   繁体   中英

Import error no module in Django

I am importing a module named python_contextual_test_manager in forms.py as follows:

from python_contextual_test_manager.main_runner import main as main_runner

Both python_contextual_test_manager.py and forms.py are in the same directory but it shows me the following error:

ImportError: No module named python_contextual_test_manager

What to do?

I think adding a dot in front of the file name should get you sorted. Like this:
from .python_contextual_test_manager.main_runner import main as main_runner .

The dot specifies that you want to import from the same folder that the file is in. Another way is to make the path absolute to the project directory, for example if all of that exists inside a Django app called app , then you could also import
from app.python_contextual_test_manager.main_runner import main as main_runner .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM