15

I've created an model Girl When I open python console and write from .models import Girl I get an error:

>>> from .models import Girl
Traceback (most recent call last):
  File "<console>", line 1, in <module>
KeyError: "'__name__' not in globals"

What do I do?

user2950593
  • 8,116
  • 13
  • 62
  • 120

1 Answers1

32

Did you try putting the app name before ".models"?

>> from [app_name].models import Girl
user3750325
  • 1,351
  • 1
  • 19
  • 35
  • 2
    Could you please explain how it fixes this problem? – dylan_fan Jun 19 '18 at 11:17
  • 7
    `.models` tries to import from `models.py` in the current directory, which if using Django shell, is the project directory. But `models.py` is actually located in the app directory. – gengkev Jun 19 '18 at 21:59