16

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
  • 9,233
  • 15
  • 67
  • 131

1 Answers1

35

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

>> from [app_name].models import Girl
user3750325
  • 1,502
  • 1
  • 18
  • 37
  • 2
    Could you please explain how it fixes this problem? – dylan_fan Jun 19 '18 at 11:17
  • 8
    `.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