[Django]-How do they run these commands in python console within Django project?

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👍

An easy way to do this:

In the Menu bar, go to Tools -> Run manage.py Task
Menu

You’ll see the results of running that command in a console below. Run your commands here.

console

👤JaredH

Leave a comment