Skip to main content

Intuitive text editing for the Django Admin.

Project description

# django-text

[![Join the chat at https://gitter.im/antonagestam/django-text](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/antonagestam/django-text?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

Intuitive text editing for the Django Admin.

:warning:

This project is in early development, will change rapidly and most likely has bugs.


## Installation

Install the package with pip.

```shell
$ pip install django-text
```

Add `text` to your installed packages.

```python
# settings.py

INSTALLED_APPS = (
# ...
'text',
)
```

Add `text.middleware.TextMiddleware` to your middleware.

```python
# settings.py

MIDDLEWARE = (
# ...
'text.middleware.TextMiddleware',
)
```

Run `migrate`.

```shell
$ python manage.py migrate
```


## Usage

### The `editable` tag

Add `editable` tags to your templates.

```html
<h1>{% editable "header" "My Header" %}</h1>

<div class="content">
{% editable "text_body" %}
</div>
```

The `editable` tag takes a default text as the second argument.
If no default text is passed, the name of the text node (i.e. the first argument)
will be used if there is no corresponding text node in the database.


### The `blockeditable` tag

You can also use the `blockeditable` tag that let's you wrap content to use
as the default text.

```html
<div class="content">
<h1>
{% blockeditable "header" %}
Read My Awesome Text
{% endblockeditable %}
</h1>

{% blockeditable "content" %}
Put your default text here!
{% endblockeditable %}
</div>
```

The `blockeditable` tags works with translation tags inside of it. So if you already
have a translated site, you can wrap your content with this tag and only
add text nodes for some of the languages that you support.


### Specifying content type

Both the `editable` and the `blockeditable` tags support specifying the content
type of its default text.

```html
{% editable "html_node" "<h1>Hello World!</h1>" "html" %}

{% blockeditable "markdown_node" "markdown" %}
# Hello there,

I can have markdown in my templates!
{% endblockeditable %}
```

If this is not provided both will default to raw text.


### Content editing

![django-text in action](/docs/printscreen.png)

Now add text nodes with the corresponding names in the Django Admin. Currently raw text, [markdown](http://daringfireball.net/projects/markdown/) and HTML is supported. The editor
is only implemented for HTML nodes, markdown and text types will show up as a normal
textarea.

Missing text nodes will be added to the database automatically when their
template tags are rendered. Blocktags will be added with their default
text and inline tags will be added with the name of the node as the text content.

To disable automatic updating of missing text nodes add the following to your settings.

```python
AUTOPOPULATE_TEXT = False
```

## Contribution

Contribution is very welcome. Use [issues](https://github.com/antonagestam/django-text/issues) to report bugs and propose features.


## License

Copyright (c) 2015 Anton Agestam. django-text is released under the MIT license.
See the LICENSE file for more information and licenses for bundled code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-text, version 1.4.0
Filename, size File type Python version Upload date Hashes
Filename, size django-text-1.4.0.tar.gz (48.2 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page