3👍
When you run the project you’re using a management command: python manage.py runserver
. To enter a console that has access to all your Django apps, the ORM, etc., use another management command: python manage.py shell
. That will allow you to import models as shown in your example.
As an additional tip, consider installing the Django extensions package, which includes a management command shell_plus
. It’s helpful, especially (but not only) in development, as it imports all your models, along with some other handy tools.
1👍
Django has a Shell management command that allows you to open a Python shell with all the Django stuff bootstrapped and ready to be executed.
So by using ./manage.py shell
you will get an interactive python shell where you can write code.
0👍
- [Django]-Django rest framework request.data raises Error
- [Django]-Django ElasticSearch DSL partial matching using nGram analyzer
- [Django]-How to apply Test Driven Development with Django Models?
- [Django]-Force django UpdateView to create an new object instead
- [Django]-Using matplotlib with Django Generic views