Django - Popular Shell Commands

A curated list with popular shell commands for Django to boost your productivity and preparation for going LIVE.

Django - A short list with popular SHELL commands
Django - A short list with 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)