百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
D

django-markupfield

> 后端框架
开源

一个用于 Django 的 MarkupField

197 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个用于 Django 的 MarkupField

================== django-markupfield

This repository has moved to Codeberg, GitHub will remain as a read-only mirror.

.. image:: https://codeberg.org/jpt/django-markupfield/workflows/Test/badge.svg

.. image:: https://img.shields.io/pypi/v/django-markupfield.svg :target: https://pypi.python.org/pypi/django-markupfield

An implementation of a custom MarkupField for Django. A MarkupField is in essence a TextField with an associated markup type. The field also caches its rendered value on the assumption that disk space is cheaper than CPU cycles in a web application.

Installation

The recommended way to install django-markupfield is with pip _

It is not necessary to add 'markupfield' to your INSTALLED_APPS, it merely needs to be on your PYTHONPATH. However, to use titled markup you either add 'markupfield' to your INSTALLED_APPS or add the corresponding translations to your project translation.

Requirements

Requires Django >= 2.2 and 3.6+

  • 1.5.x is the last release to officially support Django >> a = Article.objects.all()[0]

    a.body.raw u'fancy' a.body.markup_type u'markdown' a.body.rendered u' fancy ' print unicode(a.body)

fancy

Assignment to a.body is equivalent to assignment to a.body.raw and assignment to a.body_markup_type is equivalent to assignment to a.body.markup_type.

.. important:: Keeping in mind that body is MarkupField instance is particullary important with default or default_if_none filter for model that could be blank. If body's rendered is None or empty string ("") these filters will not evaluate body as falsy to display default text::

    {{ a.body|default:"" }}

That's because ``body`` is regular non-``None`` MarkupField instance. To let ``default`` or ``default_if_none`` filters to work evaluate ``rendered`` MarkupField attribute instead. To prevent escaping HTML for the case ``rendered`` is truethy, finish chain with ``safe`` filter::

    {{ a.body.rendered|default:""|safe }} 

.. note:: a.body.rendered is only updated when a.save() is called

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythondatabasedjangomarkdownmarkup

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类后端框架
定价开源

> 相关工具

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架