在django应用程序中嵌入任何你想嵌入的文本。

django_inlines的Python项目详细描述


那这是什么?

django inlines是一个应用程序,允许您使用include other objects和special 文本字段中的位。

它使用注册样式,因此很容易为任何应用程序设置内联 或第三方应用程序。

示例:

注册您的内联线:

from django_inlines import inlines
from django_inlines.samples import YoutubeInline

inlines.registry.register('youtube', YoutubeInline)

在您的条目中。body

<p>Check out my new video:</p>

{{ youtube http://www.youtube.com/watch?v=RXJKdh1KZ0w }}

在您的模板中:

{% load inlines %}
{% process_inlines entry.body %}

输出:

<p>Check out my new video:</p>

<div class="youtube_video">
  <object width="480" height="295">
    <param name="movie" value="http://www.youtube.com/v/RXJKdh1KZ0w&hl=en&fs=1"></param>
    <param name="allowFullScreen" value="true"></param>
    <param name="allowscriptaccess" value="always"></param>
    <embed src="http://www.youtube.com/v/RXJKdh1KZ0w&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="295"></embed>
  </object>
</div>

创建内联

内联可以是提供render方法且具有 可以接受这些参数的初始化

__init__(self, value, variant=None, context=None, template_dir="", **kwargs)

django内联带有可以创建子类的基本内联类 你自己的内线。

inlines.InlineBase

A base class for overriding to provide simple inlines. The render method is the only required override. It should return a string. or at least something that can be coerced into a string.

inlines.TemplateInline

A base class for overriding to provide templated inlines. The get_context method is the only required override. It should return dictionary-like object that will be fed to the template as the context.

If you instantiate your inline class with a context instance, it’ll use that to set up your base context.

Any extra arguments assigned to your inline are passed directly though to the context.

有关^{tt4}的示例,请参见samples.YoutubeInline。$ 子类。

模板内联呈现的模板名称与它们的名称相同 注册为。youtube内联使用inlines/youtube.html

inlines.ModelInline

A base class for creating inlines for Django models. The model class attribute is the only required override. It should be assigned a django model class.

内联示例模型:

from myapp.models import Photo

class PhotoInline(inlines.ModelInline):
  model = Photo

inlines.registry.register('photo', PhotoInline)

使用中:

{{ photo 1 }}

modelinline将对象的id作为唯一值,并将该对象传递到 上下文为object

由于模型内联将经常使用,因此有一个inline_for_model 快捷方式。它可用于将模型直接注册为内联:

from django_inlines.inlines import inline_for_model
inlines.registry.register('photo', inline_for_model(Photo))

内联语法

django内联使用此语法{{ name[:variant] value [argument=value ...] }}

name

The name the inline has been registered under. Template inlines use this as the base name for their templates.

value

Any string. It’s the requirement of the inline class to parse this string.

variant可选

Variants can be used by the inline class to alter behavior. By default any inline that renders a template uses this to check for an alternate template. ^{tt13}$ would first check for ^{tt14}$ before checking for ^{tt5}$.

arguments可选

Any number of key=value pairs are allowed at the end of an inline. These are passed directly to the template as context vars. ^{tt17}$

模板标签

搜索提供的内容并在任何位置应用内联 找到了。模板的当前上下文将传递到内联模板。

语法:

{% process_inlines entry.body [in template_dir] [as varname] }

示例:

{% process_inlines entry.body %}

{% process_inlines entry.body as body %}

{% process_inlines entry.body in 'inlines/sidebar' %}

{% process_inlines entry.body in 'inlines/sidebar' as body %}

如果给定可选的template_dir参数,则inlines将首先签入 在返回到inlines/<inline_name>.html

如果给定[作为varname],则标记不会返回任何内容,而是填充 varname在你的上下文中。然后可以对输出应用筛选器或进行测试。

设置

您可以覆盖settings.py

中的某些设置
  • INLINE_DEBUG = True:通常,内联的错误会自动失败。 将其转换为True将引发您的内联线可能产生的所有异常。 默认值:False
  • INLINES_START_TAG = '{{':内联语法中使用的开始标记。 默认值:'{{'
  • INLINES_END_TAG = '}}':内联语法中使用的结束标记。 默认值:'}}'

待办事项:

警告:django内联仍在开发中。这里的一切都是 经过良好的测试和功能,但稳定性尚未得到保证。重要的部分 还不存在。其中包括:

  • 更好的文件。
  • 在应用程序中自动发现inlines.py的管理风格。
  • 向基类添加验证挂钩。
  • 一个模型字段和一个小部件,用于验证和改进管理中的添加。

更改:

0.7.2

错误修复:

  • 现在论点正确(多亏了马丁马纳)。
  • 修正了正则表达式中偶尔会错误地拆分传递值的错误。

新的:

  • 开始标记和结束标记现在可以通过设置进行控制。

0.7.1

  • 包括来自jannis leidel的修复,所以它现在可以在pypi上工作了。谢谢詹尼斯!

0.7

  • 首次公开发行

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
异常如何在java中优雅地处理FileNotFoundexception   java线程卡在BlockingQueue上。无缘无故   类网格程序w/java   StrutsJava:动态应用Velocity脚本   java在运行时重写/禁用方面   java Apache POI无法正确读取Excel单元格中的秒数   具有不同用户权限的Java文件夹/文件创建   java我可以检查Firebase ValueEventListener onDataChanged是否已被调用吗?   尽管获得了用户权限,java Android开发文件权限仍被拒绝   java如何使用JPA映射map<EnumType,Double>?   java是否使用UI线程显示toast消息?   JAVAlang.IllegalArgumentException:不支持的元素:rss   java Android setRequestedOrientation活动和视图生命周期   安卓如何在Java中定义支票盒?   在Java中,对于大输入,字符串解析长期失败   使Java在XP中按计划任务运行读取env用户变量时出现问题   任务“:workflowsjava:NodeDriver”的梯度执行失败。main()   java如何检测是否只设置了部分属性?   在客户端web服务上使用JBossWS时,java无法找到/更改log4j的默认配置   java LibGDX写入文本文件并接收各种错误