A readline shell for the Django template language.
Project description
django-template-repl is a readline shell for the Django template language.
It is similar to a CPython shell but it interprets template code instead of
Python. It can be invoked either as a management command or with a templatetag.
To install, add 'template_repl' to your settings.INSTALLED_APPS.
The management command gives you quick access to the shell:
python manage.py templateshell
You can pass a url to the management command to assume the context of a specific location:
python manage.py templateshell -u /admin/foo/bar/
You can also provide context directly with a command line option. Here is
an example of an interactive session:
$ python manage.py templateshell -c "{'foo': 'FOO', 'bar': True}"
>>> {% if bar %}
... {{ foo }}
... {% endif %}
FOO
>>>
The templateshell management command also has a --pdb option to allow you to load
the context into a namespace and start a PDB debugger shell. This works in conjunction
with the -u (--url) and -c (--context) commands. It also provides a "vars" list that
shows the names of the context variables:
$ python manage.py templateshell -u /admin/ --pdb
...
ipdb> vars
Out[0]:
['app_path',
'error_message',
'root_path',
'title',
'MEDIA_URL',
'LANGUAGES',
'LANGUAGE_BIDI',
'LANGUAGE_CODE',
'perms',
'messages',
'user']
ipdb> print user
AnonymousUser
In addition, you can use the repl templatetag which creates a REPL that assumes the
context of the caller template. This is basically "PDB for templates":
{% load repl %}{% repl %}
You can also start a real PDB shell using the same tag by giving it a second argument
of "pdb". This loads the contex into the PDB namespace:
{% load repl %}{% repl pdb %}
It is similar to a CPython shell but it interprets template code instead of
Python. It can be invoked either as a management command or with a templatetag.
To install, add 'template_repl' to your settings.INSTALLED_APPS.
The management command gives you quick access to the shell:
python manage.py templateshell
You can pass a url to the management command to assume the context of a specific location:
python manage.py templateshell -u /admin/foo/bar/
You can also provide context directly with a command line option. Here is
an example of an interactive session:
$ python manage.py templateshell -c "{'foo': 'FOO', 'bar': True}"
>>> {% if bar %}
... {{ foo }}
... {% endif %}
FOO
>>>
The templateshell management command also has a --pdb option to allow you to load
the context into a namespace and start a PDB debugger shell. This works in conjunction
with the -u (--url) and -c (--context) commands. It also provides a "vars" list that
shows the names of the context variables:
$ python manage.py templateshell -u /admin/ --pdb
...
ipdb> vars
Out[0]:
['app_path',
'error_message',
'root_path',
'title',
'MEDIA_URL',
'LANGUAGES',
'LANGUAGE_BIDI',
'LANGUAGE_CODE',
'perms',
'messages',
'user']
ipdb> print user
AnonymousUser
In addition, you can use the repl templatetag which creates a REPL that assumes the
context of the caller template. This is basically "PDB for templates":
{% load repl %}{% repl %}
You can also start a real PDB shell using the same tag by giving it a second argument
of "pdb". This loads the contex into the PDB namespace:
{% load repl %}{% repl pdb %}
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-template-repl-0.2.0.tar.gz
.
File metadata
- Download URL: django-template-repl-0.2.0.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4cf6d3674118af97387dfcc75bb0fb2bf9b6a1bf5a678b191cc45f7ac89de700 |
|
MD5 | d0533cb1cc054afcf0c1f02dee805c58 |
|
BLAKE2b-256 | 2fed56a19af2efb4702bc3a8671ae06c03e1c0621814be8ab752dc6967020ad7 |