使用 django 在文件中使用标记
我目前正在使用 django 开发一个网站,我的问题是该网站必须从使用 php 脚本移植到使用 django。 虽然网站内容已经被以前的维护者维护得很好,但我必须对已经包含大量内容的文件使用 markdown,例如主页被分为目录中的三个文件,例如 a.html、b .html、c.html 虽然它们都包含简单的文本内容,但我是否必须单独渲染它们,我应该使用 view.py 文件来解析结构还是使用模板来解析结构,真正的问题是如何解析模板内文件的内容
我编写了一个模板:
{% extends "catalog.html" %}
{% block content %}
<div class="yui-g" id="masthead">
<div id="main_feature">
<div id="main_feature_content">
{% include "features/main.html" %}
</div>
</div>
</div>
<div class="yui-g" id="main_information">
<div class="yui-g" style="float: left; width: 49%">
{% include "features/about.html" %}
</div>
<div class="yui-g" style="float: right; width: 49%">
<h2>Recent Headlines</h2>
<a href="/news">More</a>
</div>
</div>
<div class="yui-g" id="features_container">
<div id="features">
<div class="feature feature_developer">
<div class="feature_content">
{% include "features/1.html" %}
</div>
</div>
<div class="feature feature_middle feature_community">
<div class="feature_content">
{% include "features/2.html" %}
</div>
</div>
<div class="feature feature_community">
<div class="feature_content">
{% include "features/3.html" %}
</div>
</div>
</div>
</div>
{% endblock %}
这是我需要解析的包含文件:- {% include "features/about.html" %} 但任何人都会明白这只会显示文件内容而不是解析的 html。感谢您提前的帮助
I am currently working on a website using, django, my problem is that the site has to be ported from using php scripts to using django.
Though the site content has been well maintained by the previous maintainer, I have to use markdown for files that already having a HUGE amount of content in them, like the main page is divided into three files inside a directory, like a.html, b.html, c.html though they all contain simple text content, do I have to render them all seperately, should i use the view.py file for parsing the structure or use a template for the same, the real question is how to parse the contents of a file INSIDE the template
I wrote a template:
{% extends "catalog.html" %}
{% block content %}
<div class="yui-g" id="masthead">
<div id="main_feature">
<div id="main_feature_content">
{% include "features/main.html" %}
</div>
</div>
</div>
<div class="yui-g" id="main_information">
<div class="yui-g" style="float: left; width: 49%">
{% include "features/about.html" %}
</div>
<div class="yui-g" style="float: right; width: 49%">
<h2>Recent Headlines</h2>
<a href="/news">More</a>
</div>
</div>
<div class="yui-g" id="features_container">
<div id="features">
<div class="feature feature_developer">
<div class="feature_content">
{% include "features/1.html" %}
</div>
</div>
<div class="feature feature_middle feature_community">
<div class="feature_content">
{% include "features/2.html" %}
</div>
</div>
<div class="feature feature_community">
<div class="feature_content">
{% include "features/3.html" %}
</div>
</div>
</div>
</div>
{% endblock %}
this is the included file i needed to parse :- {% include "features/about.html" %}
but anyone will understand that this will only display the file contents not the parsed html. Thanks for the help in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
{% include %} 标签仅处理 Django 模板文件,不支持任何自定义处理,例如处理 markdown 本身。您有几种选择:
{% load markup %}{% filter markdown %}
和{% endfilter %}
将所有 Markdown 内容包装在包含的模板中>。 过滤器标签将指定的过滤器应用于它的内容。您将需要在每个模板的开头添加{% load markup %}
行,因为每个模板都需要加载它使用的附加标记库。{{ aboutcontent|markdown }}
的操作(其中aboutcontent
是您的视图提供的上下文变量)。{{ aboutcontent }}
。The {% include %} tag only processes Django template files, and does not support any custom processing such as handling markdown in and of itself. You have a few options:
{% load markup %}{% filter markdown %}
and{% endfilter %}
. The filter tag applies the specified filter(s) to its contents. You will need the{% load markup %}
line in the beginning of each template, as each template needs to load the additional tag libraries that it uses.{{ aboutcontent|markdown }}
in your template (whereaboutcontent
is the context variable your view provided).{{ aboutcontent }}
.