Question

I have this master html template:

<!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>

this is the test.py file:

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({})

I'm a complete n00b at templating and web design. lets say i run this via any of python web server like flask on localhost:port/test

Nothing shows up.

Why? And what is this @path_for in wheezy.template? Do I need to include @require(path_for) or anything else? is that necessary to server static files in the html file to define all the files in a specific folder-> 'static'

or can they be accessed from where they are now, as in the code above?

Was it helpful?

Solution

You had lots of questions. I'll answer even though you may not care anymore...

If you have correctly configured Flask, and served that template on the route/url 'test', then nothing would appear as you have not defined a <body> with any content in the html.

In wheezy.templates, you access local variables/functions with the @my_variable syntax (ie you prefix it with an @ symbol). If you want to access a variable that was passed to the template as part of the context, you need to require it first, @require(my_variable). Your example uses an empty dict as the context, so there would be no variables to access/require.

path_for is part of wheezy.routing, not wheezy.templates. It is used for getting the url of a named route (ie you could do @path_for('test'), and it would return localhost:1234/test. Using path_for would only make sense if you are using the complete wheezy.web framework (which uses wheezy.routing and wheezy.templates). Flask would have its own functions for doing this (I'm not sure what they are though, I don't use Flask). You would need to pass these functions into the template via the context, then @require them to use them though (or make some custom extension for wheezy.template).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top