Giter Club home page Giter Club logo

django-shell's Introduction

django_shell

From time to time I use the manage.py shell command to launch simple one-time tasks within my Django projects in the non-interactive mode. For example:

$ echo 'from django_app.tasks import procmail; procmail()' | ./manage.py shell

It's possible to run python scripts too:

$ echo 'execfile("/path/to/migrations/01-fix-stupid-bug.py")' | ./manage.py shell

It is fast and easy, than write real application management commands. But now I have some restrictions:

  1. Annoying syntax for a command execution.

  2. I can't pass additional command line arguments because shell refuses them:

    $ echo 'import sys; print sys.argv' | ./manage.py shell --foo
    ...
    manage.py: error: no such option: --foo
    
  3. The shell pollutes both stdin and stdout with banners from interactive python:

    $ echo '' | ./manage.py shell
    Python 2.5.2 (r252:60911, Jan 20 2010, 23:14:04) 
    [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    (InteractiveConsole)
    
    >>> >>> 
    

I suppose the manage.py shell command line interface should be similar to regular python.

Should execute python code:

$ ./manage.py shell -c 'from django.db.models.loading import get_models; print get_models()'

Should execute python files:

$ ./manage.py shell /path/to/migrations/01-fix-stupid-bug.py

Should execute python modules:

$ ./manage.py shell -m smtpd -n -c DebuggingServer localhost:1025

Should execute python code from stdin:

$ echo 'from django.db.models.loading import get_models; print get_models()' | ./manage.py shell -

Under *nix-like environments it's possible to use manage.py shell as interpreter. Just put manage.py into the PATH:

#!manage.py shell

from django.db.models.loading import get_models, get_apps
print "Models", get_models()
print "Applications", get_apps()

-- Will, whether the work in this area helpful for Django?

django-shell's People

Contributors

generalov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.