I am importing models in django shell API but i get the below error. Here is how it occurs:
python manage.py shell
from .models import Device
I get:
File "<console>", line 1, in <module> KeyError: "'__name__' not in globals"
Try putting the app name before ".models". Here .models trying to import from models.py in the current directory but models.py is actually located in the app directory.
>> from [app_name].models import Device
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.