Django - Popular Shell Commands

Hello! For newcomers, Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. It's widely used for building web applications due to its simplicity, flexibility, and extensive documentation.

Need help coding an MVP or a Complete Product using Django? Give us 5 minutes of your time & we`ll get back to you soon.

The SHELL commands mentioned in this article aim to help developers code their projects faster and gain more control during the whole process from configuration, and DB access to LIVE deployment. Thanks for reading!

πŸ‘‰ shell

$ python manage.py shell

Opens up a Python shell with Django's environment loaded, allowing you to interactively execute Python code within the context of your Django project.


πŸ‘‰ dbshell

$ python manage.py dbshell

Opens up a Python shell with Django's environment loaded, allowing you to interactively execute Python code within the context of your Django project.


πŸ‘‰ startproject <project_name>

$ python manage.py startproject MyDjangoProject

Creates a new Django project with the specified name.


πŸ‘‰ startapp <app_name>

$ python manage.py startapp MyNewApp

Creates a new Django app within your project, with the specified name.


πŸ‘‰ runserver

$ python manage.py runserver 

Starts the development server, allowing you to run your Django project locally for testing and development purposes.


πŸ‘‰ createsuperuser

$ python manage.py createsuperuser

Creates a new superuser account for accessing the Django admin interface.


πŸ‘‰ makemigrations

$ python manage.py makemigrations

Generates database migration files based on changes you've made to your models.


πŸ‘‰ migrate

$ python manage.py migrate

Applies database migrations, updating your database schema to match the changes in your models.


πŸ‘‰ inspectdb

$ python manage.py inspectdb

Auto-generates Django models by introspecting a legacy database, which is useful when integrating Django into a project with a pre-existing database.


πŸ‘‰ createsuperuser

$ python manage.py createsuperuser

Creates a new superuser account for accessing the Django admin interface.


πŸ‘‰ collectstatic

$ python manage.py collectstatic

Collects static files from your Django apps into a single location for deployment.


πŸ‘‰ test

$ python manage.py test

Runs tests for your Django project, including any tests you've written using Django's testing framework.


πŸ‘‰ showmigrations

$ python manage.py showmigrations

Displays a list of all migrations and their status (applied or not applied).


πŸ‘‰ dumpdata

$ python manage.py dumpdata

Creates a JSON or YAML representation of the data in your database (aka backups).


πŸ‘‰ loaddata <fixture>

$ python manage.py loaddata INPUT_FILE

Loads data from a fixture file into your database.


πŸ‘‰ sqlflush

$ python manage.py sqlflush

Generates SQL to delete all data from the database (useful for resetting the database during development).


πŸ‘‰ check

$ python manage.py check

Check for any issues with your Django project, such as syntax errors, potential problems, and deployment readiness.


πŸ‘‰ sendtestemail

$ python manage.py sendtestemail

Test the email delivery using the address specified in your settings, verifying that the project configuration is correct.


πŸ‘‰ changepassword

$ python manage.py changepassword <username>

This command allows to update the password for the user via the CLI.


πŸ‘‰ diffsettings

$ python manage.py diffsettings

Displays differences between the current settings file and Django's default settings.


πŸ‘‰ shell_plus

$ python manage.py shell_plus

Opens an enhanced Python shell with additional features provided by third-party packages like IPython and Django extensions.


πŸ‘‰ runscript

$ python manage.py runscript

Executes a Python script within the context of your Django project.


Conclusion

Knowing and using these Django commands might improve our development workflow, by allowing more efficient project management and debugging. The mentioned command offers unique benefits in different contexts like setting up the initial project, adding new applications, managing the database, and critical checks before going LIVE.


Thanks for reading!Β For more resources, feel free to access:
  • πŸ‘‰Β AppSeed, a platform already used by 8k registered developers
  • πŸ‘‰ Build apps withΒ Django App GeneratorΒ (free service)