通过wheezy.template提供静态文件css和js?

时间:2014-01-22 15:03:26

标签: python css template-engine

我有这个主html模板:

<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">

    <title>Start Bootstrap - SB Admin Version 2.0 Demo</title>

    <!-- Core CSS - Include with every page -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="font-awesome/css/font-awesome.css" rel="stylesheet">

    <!-- SB Admin CSS - Include with every page -->
    <link href="css/sb-admin.css" rel="stylesheet">
<!-- Core Scripts - Include with every page -->
    <script src="js/jquery-1.10.2.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>

    <!-- SB Admin Scripts - Include with every page -->
    <script src="js/sb-admin.js"></script>

</head>

这是test.py文件:

from wheezy.template.engine import Engine
from wheezy.template.ext.core import CoreExtension
from wheezy.template.loader import FileLoader

T = ['where/project/folderbase/is']


engine = Engine(
    loader=FileLoader(T),
    extensions=[CoreExtension()]
)

master_template = engine.get_template(r'master.htm')

@route('/test')
def login_name():
    return master_template.render({})

我是模板和网页设计的完整n00b。 假设我通过 localhost:port / test

上的任何python web服务器运行

什么都没有出现。

为什么呢? @path_for中的wheezy.template是什么? 我是否需要包含@require(path_for)或其他内容? 是必要的服务器html文件中的静态文件来定义特定文件夹中的所有文件 - &gt; '静态'

或者可以从现在的位置访问它们,如上面的代码所示?

1 个答案:

答案 0 :(得分:1)

你有很多问题。即使你可能不在乎,我也会回答......

如果您已正确配置Flask,并在路由/网址&#39;测试&#39;上提供该模板,则不会显示任何内容,因为您未在html中定义任何内容<body>

在wheezy.templates中,使用@my_variable语法访问局部变量/函数(即用@符号作为前缀)。如果要访问作为上下文的一部分传递给模板的变量,则需要首先要求@require(my_variable)。您的示例使用空dict作为上下文,因此没有变量可以访问/ require。

path_for是wheezy.routing的一部分,而不是wheezy.templates。它用于获取命名路由的url(即你可以执行@path_for('test'),它将返回localhost:1234/test。使用path_for只有在使用完整的wheezy.web框架时才有意义(使用wheezy.routing和wheezy.templates)。烧瓶将有自己的功能(我不知道它们是什么,我不使用Flask)。你需要将这些功能传递给通过上下文模板,然后@求他们使用它们(或者为wheezy.template制作一些自定义扩展)。

相关问题