django-term

In browser term for Django


Keywords
django, terminal, django-instant
License
MIT
Install
pip install django-term==0.1.3

Documentation

Django Term

In browser terminal for Django that enables custom commands

Install

Dependency: Django Instant for the websockets: install doc

pip install django-term

Add "term", to installed apps:

Set the urls

from instant.views import instant_auth

urlpatterns = [
   url('^terminal/', include('term.urls')),
   url('^instant/', include('instant.urls')),
   url('^centrifuge/auth/$', instant_auth, name='instant-auth'),
]

Add to settings.py:

SITE_SLUG = "mysite"
INSTANT_SUPERUSER_CHANNELS = [
 ["$" + SITE_SLUG + "_terminal", ["/terminal"]]
]

Create a templates/instant/handlers/$mysite_terminal.js whith this content:

{% include "term/handlers.js" %}

Run the websockets server and go to /terminal/

Commands

Note: to use the commands from third-party apps your must have these apps installed

help: display info about the available commands

ping: ping the server

clear: clears the screen

From Django Introspection:

inspect: gives infos about an app or model. Params: appname or appname.Modelname: ex: inspect auth.User

From Django Dex:

replicatedb: replicates the 'default' db into a sqlite 'replica' db

Create a command

Create a terminal folder in any app. Create a commands.py file inside this directory:

from term.commands import Command, rprint

def run_hello(request, cmd_args):
   rprint("Hello world")
 
# Args are the command name, the runner function and the help text
c1 = Command("hello", run_hello, "Hello world command")
COMMANDS = [c1]

Your command will be detected at startup and enabled in the terminal

To debug a command during developement use TERM_DEBUG_MODEL = "mymodel"

Apps that have terminal commands:

django-introspection: get infos about Django objects

django-dex: database export tools

django-jobrunner: experimental asynchronous jobs runner

Customize the ui

To customize the colors use the terminal/colors.css template

Screenshot

Terminal