Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Shell API KeyError

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"

like image 361
Andd Avatar asked Dec 02 '22 09:12

Andd


1 Answers

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
like image 115
Abu Sayem Avatar answered Dec 04 '22 05:12

Abu Sayem