ModuleNotFoundError: No module named 'api'

Viewed 15830

I created a Django project inside of api folder called bucks:

api
|____ categories/
    |____ __init__.py
    |____ ...
    |____ models.py
    |____ tests.py
    |____ views.py
|____ .../
|____ bucks/
|____ users/
    |____ __init__.py
    |____ ...
    |____ models.py
    |____ signals.py
    |____ tests.py
    |____ views.py
|____ __init__.py
|____ manage.py
webroot
|___ ...

And in my bucks folder inside the api, I am doing the following:

from api.users.views import CustomObtainAuthToken

But I am facing an error when I run makemigrations:

ModuleNotFoundError: No module named 'api'

I also tried to add users.app.UsersConfig in my INTALLED_APPS, but then, this error:

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

So I am in this impass. I couldn't find another way to import CustomObtainAuthToken, it'd only allow me to access it through that syntax.

2 Answers

check your settings file if the name of the app is correct or not

As mentioned in the documentation...

If you need to have test modules with the same name, you might add init.py files to your tests folder and subfolders, changing them to packages

So you just need to add an empty __init__.py in all your tests folders and it will be it.

Related