edx-platform中的python模板语法

时间:2014-08-19 06:46:13

标签: python django edx

我正在学习edx平台的lms服务。 它使用的是python 2.7 + django。 通常,使用python模板语法如下:

{% extends "base_generic.html" %}
{% block title %}{{ section.title }}{% endblock %}

{% block content %}
<h1>{{ section.title }}</h1>

{% for story in story_list %}
<h2>
  <a href="{{ story.get_absolute_url }}">
    {{ story.headline|upper }}
  </a>
</h2>
<p>{{ story.tease|truncatewords:"100" }}</p>
{% endfor %}
{% endblock %}

但edx-platform使用如下:

<%namespace name='static' file='static_content.html'/>
<%!
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from courseware.courses import course_image_url, get_course_about_section
%>
<%page args="course" />
<article id="${course.id.to_deprecated_string()}" class="course">
  %if course.is_newish:
    <span class="status">${_("New")}</span>
  %endif
  <a href="${reverse('about_course', args=[course.id.to_deprecated_string()])}">
  <div class="inner-wrapper">

我不懂语法。 也许单线是&#34;%&#34; ,多行是&#34;&lt; %%&gt;&#34; 这是python语法?如何使用该语法?

1 个答案:

答案 0 :(得分:4)

edx-platform正在使用mako模板语言。

Mako是一个用Python编写的模板库。它提供了一种熟悉的非XML语法,可以编译成Python模块以获得最佳性能。 Mako的语法和API借鉴了许多其他人的最佳想法,包括Django模板,Cheetah,Myghty和Genshi。从概念上讲,Mako是一种嵌入式Python(即Python服务器页面)语言,它简化了组件化布局和继承的熟悉思想,以生成可用的最直接和最灵活的模型之一,同时保持与Python调用和作用域语义的紧密联系。 / p>

请参阅http://www.makotemplates.org/docs/

上的Mako文档