Login

Tag "shell"

Snippet List

Facebook shell

This adds an 'fbshell' management command which starts up a Python shell with an authenticated [pyfacebook](http://code.google.com/p/pyfacebook/) instance ready to make requests. This is very useful for testing out facebook requests or performing administration tasks without hooking a debugger into your application. This snippet should be saved to /yourproject/management/commands/fbshell.py See [custom management commands](http://docs.djangoproject.com/en/dev/howto/custom-management-commands/) for a description of how this works. If you are already using pyfacebook in your app then you'll already have the right settings, so just run : $ python manage.py fbshell A browser window will pop up, prompting you for authentication (unless you're already logged in to facebook). Press enter in the shell when you're finished this, and you'll be dropped into a shell with the session key, uuid, and name printed. Now you can use the facebook instance: >>> facebook.friends.get() >>> [...] If you haven't used pyfacebook in your app, you'll need at least the following settings in your settings.py FACEBOOK_API_KEY = 'your_api_key' FACEBOOK_SECRET_KEY = 'your_secret_key'

  • management
  • shell
  • facebook
  • command
Read More

testshell

This commands runs a Python interactive interpreter with test database and data from the given fixture(s). It is usable if you want to play with test database. See also testserver docs

  • fixtures
  • shell
  • testshell
Read More

Use django-admin.py instead of manage.py

A lot of people new to Django don't realize that `manage.py` is [just a wrapper](http://www.djangoproject.com/documentation/django-admin/) around the `django-admin.py` script installed with Django and isn't needed. (You may need to symlink `django-admin.py` to someplace in your system `PATH` such as `/usr/local/bin`.) The most important thing it does is to set your `PYTHONPATH` and `DJANGO_SETTINGS_MODULE` environment variables before calling `django-admin.py`. Those same settings are needed when you move your site on to a production server like Apache, so it is important to know how they work. This shell function sets those variables for you. Put it in your `.zshrc` or bash startup script. It works for both the monolithic project style and the lightweight app style of Django development [[1](http://www.pointy-stick.com/blog/2007/11/09/django-tip-developing-without-projects/)], [[2](http://www.b-list.org/weblog/2007/nov/09/projects/)]. This function isn't fancy; drop a comment if you have an improvement. Written for zsh and tested with bash 3.1.17.

  • bash
  • shell
  • zsh
Read More

Alternate method of autoloading Django models in ipython

This is a little improvement to the [idea](http://www.djangosnippets.org/snippets/540/) from sheats a few days ago. I like it over the previous solutions because it doesn't involve doing anything other than running `./manage.py shell` inside your project directory. You don't have to create any files anywhere or remember to call anything, and `ipython` still works fine outside of a Django project. Throw this code in `~/.ipython/ipy_user_conf.py` (`ipythonrc` has apparently been deprecated).

  • django
  • model
  • manage.py
  • shell
  • ipython
Read More

Autoload Django Models When Using ./manage.py shell

It's a pain to import all the Django models you want to use in the Python shell every time you start it. Here's how you can get IPython to autoload all your Django models for you every time you start the shell using ./manage.py shell. Put the code in a .py file in the root of your project. Then tell IPython to load the script in ~/.ipython/ipythonrc in the "Python files to load and execute" section.

  • import
  • shell
  • interpreter
  • autoload
Read More

PyCrust Shell

I thought it would be a neat idea to use the PyCrust shell for interacting with my models, instead of using the plain old shell. So what I did, is take a copy of the file: django/core/management/commands/shell.py Altered it, and saved it as: django/core/management/commands/pycrust.py For this to work, you should have pycrust installed (python-wxtools in ubuntu) and save this snippet as django/core/management/commands/pycrust.py, then run as follows: ./manage.py pycrust instead of ./manage.py shell Have fun!

  • pycrust
  • shell
Read More

6 snippets posted so far.