在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第三方库


热门话题
ArrayList Java中的搜索字符串   另一个web应用程序的java访问会话   另一个应用程序中的活动和服务之间的java通信   java根据Json字符串类型将Json字符串转换为对象   eclipse如何解决java中的错误异常。lang.NoSuchMethodError:'java。字符串javax。摆动JOptionPane。showInputDialog(java.lang.String)'   线程“main”java中的安卓异常。lang.NoClassDefFoundError:org/codehaus/jackson/JsonParseException   java如何在安卓 emulator上显示Mat图像?使用NDK   Java在本地读取测试源文件,但在服务器上读取失败   java dowhile循环用于计算输入数字中的数字。故障排除代码   JAva初学者在编写获取成本的方法时遇到困难   java是shell游戏。我如何让物体移动,特别是在特定的曲线上,但顺序是随机的?   java如何区分两个同名的JButton   java为什么我在Spring Boot中需要一个接口?   java将文件路径插入数据库将删除\   使用InterfaceType初始化java对象   java如何部署一个分为Angular、Spring Boot和MySQL的项目?   java如何使用Symja解决不等式?