django-md-field
A Django model field that integrates Python-Markdown for handling Markdown content.
Requirements
- Python: >=3.10, <4
- Django: >=4.2, <6.0
Installation
pip install django-md-field
Usage
Basic Usage
from django.db.models import Model
from markdown_field import MarkdownField
class Post(Model):
body = MarkdownField("body")
Accessing Content
# Create a post with Markdown content
>>> post = Post.objects.create(body="## Heading\n\nThis is a paragraph.")
# Access the raw Markdown text
>>> post.body.text
'## Heading\n\nThis is a paragraph.'
# Access the rendered HTML
>>> post.body.html
'<h2>Heading</h2>\n<p>This is a paragraph.</p>'
# Access table of contents (if TOC extension is enabled)
>>> post.body.toc
'<li><a href="#heading">Heading</a></li>'
Configuring Markdown Extensions
You can configure Markdown extensions in two ways:
- In your Django settings (
settings.py):
from markdown.extensions.toc import TocExtension
from django.utils.text import slugify
MARKDOWN_FIELD = {
"extensions": [
TocExtension(slugify=slugify, toc_depth=3),
"pymdownx.highlight",
"pymdownx.arithmatex",
],
"extension_configs": {
"pymdownx.highlight": {
"linenums_style": "pymdownx-inline",
},
"pymdownx.arithmatex": {
"generic": True,
},
},
}
- Directly in the model field, this will override the
MARKDOWN_FIELDsetting insettings.py:
from markdown.extensions.toc import TocExtension
from django.utils.text import slugify
body = MarkdownField(
"body",
extensions=[
TocExtension(slugify=slugify, toc_depth=3),
"pymdownx.highlight",
"pymdownx.arithmatex",
],
extension_configs={
"pymdownx.highlight": {
"linenums_style": "pymdownx-inline",
},
"pymdownx.arithmatex": {
"generic": True,
},
},
)
For more information about available extensions, see:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for django-md-field 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_md_field-0.1.0.tar.gz | 12.5 kB | Without provenance | Details for django_md_field-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_md_field-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_md_field-0.1.0-py3-none-any.whl |
Total release size: 16.8 kB
Release files / django_md_field-0.1.0.tar.gz
| Download URL | django_md_field-0.1.0.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87dff61316dfd8825b93793b91de2b9fe7e2d7f3b52478ed751565931195c2ff
|
|
BLAKE2b-256 checksum How to use checksums |
0f65bf295822108b99b2cd7addaa6a4c0cea8faeec51dfd328bab2aef08012c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.3
|
Release files / django_md_field-0.1.0-py3-none-any.whl
| Download URL | django_md_field-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
041cd2e55551ab6aa8085ffd1819a9036de7f832f29e66ef3a0eb649c6c7bfc5
|
|
BLAKE2b-256 checksum How to use checksums |
037c36c5d78a382b4b1a80b6596c7020b0eafeb26b43514cece08deb904d4e2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.3
|
Security for django-md-field 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.