简体   繁体   English

ModuleNotFoundError: 没有名为“api”的模块

[英]ModuleNotFoundError: No module named 'api'

I created a Django project inside of api folder called bucks :我在名为bucksapi文件夹中创建了一个 Django 项目:

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:api内的bucks文件夹中,我正在执行以下操作:

from api.users.views import CustomObtainAuthToken

But I am facing an error when I run makemigrations :但是当我运行makemigrations时我遇到了一个错误:

ModuleNotFoundError: No module named 'api' ModuleNotFoundError: 没有名为“api”的模块

I also tried to add users.app.UsersConfig in my INTALLED_APPS , but then, this error:我还尝试在我的INTALLED_APPS添加users.app.UsersConfig ,但是,这个错误:

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. django.core.exceptions.AppRegistryNotReady:应用程序尚未加载。

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.我找不到另一种导入CustomObtainAuthToken ,它只允许我通过该语法访问它。

如果应用程序的名称正确,请检查您的设置文件

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如果您需要具有相同名称的测试模块,您可以将init .py 文件添加到您的测试文件夹和子文件夹中,将它们更改为包

So you just need to add an empty __init__.py in all your tests folders and it will be it.所以你只需要在你所有的测试文件夹中添加一个空的__init__.py就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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