Giter Club home page Giter Club logo

django-admin-shell's Introduction

django-admin-shell

https://travis-ci.org/djk2/django-admin-shell.svg?branch=master Requirements Status

Django application can execute python code in your project's environment on django admin site. You can use similar as python manage shell without reloading the environment.

  • Tested by tox with:
    • Python :2.7, 3.4
    • Django : 1.9, 1.10, 1.11, 2.0-dev
  • Require:
    • Django >= 1.9
  • Tested on browsers
    • OK - Firefox 50.1.0 - Ubuntu 14.04
    • OK - Firefox 31.1 - CentOS 6.4
    • OK - Chromium 53.0 - Ubuntu 14.04
    • OK - Microsoft Edge 38 - Windows 10
    • OK - Internet Explorer 11.0 - Windows 8.1
    • OK - Internet Explorer 10.0 - Windows 7
    • OK - Internet Explorer 9.0 - Windows 7
    • ERR - Internet Explorer 8.0 - Windows 7 (javascripts not working / console work properly)

Screens

Django admin shell view

Shell in action

https://raw.githubusercontent.com/djk2/django-admin-shell/master/doc/static/youtube.png

Install

  1. Install:

    pip install django-admin-shell
    
    or
    
    pip install git+https://github.com/djk2/django-admin-shell.git
    
    or after download zip
    
    pip install django-admin-shell.zip
    
  2. Add django_admin_shell to your INSTALLED_APPS setting

settings.py

INSTALLED_APPS = [
    ...
    'django_admin_shell',
    ...
]
  1. Add the django_admin_shell urls to your root url patterns (above admin/) :

urls.py

urlpatterns = [
    url(r'^admin/shell/', include('django_admin_shell.urls')),
    ...
    url(r'^admin/', admin.site.urls),
]

Usage

  • shell is available on url: /admin/shell
  • On default settings user must be authenticated to django admin site and User must have superuser permission and DEBUG mode must be set on True.

Note

Make sure that in your project session is enable

More about session and how enabling session read here : https://docs.djangoproject.com/en/dev/topics/http/sessions/

Usualy default session in django project is enable

Settings

ADMIN_SHELL_ENABLE

type : bool

default : True

If shell is enable or disable. When application is disable then url: /admin/shell return Http404 Not found

ADMIN_SHELL_ONLY_DEBUG_MODE

type : bool

default : True

If flag is set on True, then shell is available only in DEBUG mode.

If debug mode is required and debug mode is disabled then url: /admin/shell will return Http 403 Forbidden

ADMIN_SHELL_ONLY_FOR_SUPERUSER

type : bool

default : True

If flag is set on True, then shell is available only for user with superuser permission.

If superuser is required and user not have permission then url: /admin/shell will return Http 403 Forbidden

ADMIN_SHELL_OUTPUT_SIZE

type : integer

default : 250

Flag determines how many outputs can be remember.

ADMIN_SHELL_SESSION_KEY

type : string

default : django_admin_shell_output

Name for key in session where is stored history last executed codes.

Code examples

  • show django settings:

    from django.conf import settings
    
    for key in dir(settings):
        val = getattr(settings, key, None)
        print(key, "=", val)
    
  • run command in operating system and take output:

    import os
    
    os.system('date > /tmp/admin_console.tmp')
    os.system('echo ------- >> /tmp/admin_console.tmp')
    os.system('who >> /tmp/admin_console.tmp')
    os.system('echo ------- >> /tmp/admin_console.tmp')
    os.system('ps aux | grep python >> /tmp/admin_console.tmp')
    
    with open('/tmp/admin_console.tmp', 'r') as f:
        print(f.read())
    
  • run big python code (get python source from website):

    import requests
    
    req = requests.get('http://foo.bar.com/example.py')
    if req.status_code == 200:
        code = req.text
        print(code, '\n------------\n')
        exec(code)
    

Useful for me:

Similar projects:

django-admin-shell's People

Contributors

djk2 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.