6👍
I don’t know about ipythonrc, but if you only need the models, you could use django-extensions
. After you install it, you’ve got a plethora of new managment commands, including shell_plus
, which will open a ipython session and autoload all your models:
python manage.py shell_plus
1👍
BryanWheelock Your solution won’t work because your shell is the result of the spawn not a direct interatction with it. What you want to do is this – or at least this is what I do.
Within your workspace (the place where you type python manage.py shell
) create a ipythonrc file. In it put the following:
include ~/.ipython/ipythonrc
execute from django.contrib.auth.models import User
# .
# .
# .
execute import_some module_name model1 model2
For example I also add the following lines in mine..
# Setup Logging
execute import sys
execute import logging
execute loglevel = logging.DEBUG
execute logging.basicConfig(format="%(levelname)-8s %(asctime)s %(name)s %(message)s", datefmt='%m/%d/%y %H:%M:%S', stream=sys.stdout )
execute log = logging.getLogger("")
execute log.setLevel(loglevel)
execute log.debug("Logging has been initialized from ipythonrc")
execute log.debug("Root Logger has been established - use \"log.LEVEL(MSG)\"")
execute log.setLevel(loglevel)
execute log.debug("log.setlevel(logging.DEBUG)")
execute print ""
This allows you to use logging in your modules and keep it DRY. Hope this helps.
- [Django]-ImportError: No module named context_processors
- [Django]-Can this variable really be "referenced before assignment"
- [Django]-Django Import/Export to multiple Models (foreignkey)
- [Django]-Is there a simple way to create Chained Dynamic Drop Down List in Django Admin Site?
0👍
shell_plus
command of django-extensions can import the model automatically, but it seems can not load the profile of ipython. I have did some hacky job to make this done.
use start_ipython
to launch ipython shell instead of embed
and pass some arguments to it.
I have also wrote a blog post, you can find the detail here
- [Django]-Mod_wsgi (3.4-14) / Apache 2.4.12 / Red Hat (6.7) / Django 1.8.2 hanging under load
- [Django]-No module named wsgi
- [Django]-Django multitenant: how to customize django setting "ACCOUNT_EMAIL_VERIFICATION" per tenant?