When I run manage.py shell on my Django project to take a peek at something there are common imports that I always want to run at the start of the shell (e.g. I always want to import my model files.) How can I have these run automatically everytime I run the shell command?
2nd related question, when I hit the up arrow I get the "^A" character instead of the previously run command in the manage.py shell (and in my regular python shell), how can I fix this so it loads the previous command like on the Linux/Unix command line?
In addition, manage.py is automatically created in each Django project. It does the same thing as django-admin but also sets the DJANGO_SETTINGS_MODULE environment variable so that it points to your project's settings.py file.
To run a task of the manage.py utilityOn the main menu, choose Tools | Run manage.py task, or press Ctrl+Alt+R . The manage.py utility starts in its own console. Type the name of the desired task.
Manage.py in Django is a command-line utility that works similar to the django-admin command. The difference is that it points towards the project's settings.py file. This manage.py utility provides various commands that you must have while working with Django.
The django-admin.py script should be on your system path if you installed Django via its setup.py utility. If it's not on your path, you can find it in site-packages/django/bin within your Python installation.
Auto importing frequently used packages in python manage.py shell_plus
Example:
# local_settings
SHELL_PLUS_PRE_IMPORTS = (
('<app_name>.models', '*'),
('<app_name>.forms', '*'),
('<app_name>.views', '*'),
('django.core.urlresolvers', '*'),
('django.db', 'connection'),
('django.db', 'reset_queries'),
)
SHELL_PLUS_DONT_LOAD = ['<app_name>', '<app_name>']
Reference:
https://github.com/django-extensions/django-extensions/blob/master/docs/shell_plus.rst
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With