Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to serve templates for custom routes ? #224

Closed
parthaaptuz opened this issue Dec 23, 2014 · 2 comments
Closed

How to serve templates for custom routes ? #224

parthaaptuz opened this issue Dec 23, 2014 · 2 comments

Comments

@parthaaptuz
Copy link

No description provided.

@parthaaptuz parthaaptuz changed the title How to server templates for custom routes ? How to serve templates for custom routes ? Dec 23, 2014
@Alerion
Copy link

Alerion commented Jan 30, 2015

You can change templates loader:

import jinja2
import os
from flask import render_template
from locust import web

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
my_loader = jinja2.ChoiceLoader([
    jinja2.FileSystemLoader(os.path.join(PROJECT_ROOT, 'templates')),
    web.app.jinja_loader,
])
web.app.jinja_loader = my_loader


@web.app.route("/stats")
def stats():
    return render_template('stats.html')

Really you can redefine index.html and change locust home page. Problem is that there is no [easy] way to extend default index.html, so just copy its content from source code. Then you can add {% block %} and use index.html as a base template for your stats.html. I think developers should add such blocks to default index.html, so it is easy to use it as a default template for your custom pages and redefine blocks if you need.

@parthaaptuz
Copy link
Author

Thank you very much

On Fri, Jan 30, 2015 at 7:57 PM, Dmytro Kostochko [email protected]
wrote:

You can change templates loader:

import jinja2import osfrom flask import render_templatefrom locust import web

PROJECT_ROOT = os.path.dirname(os.path.abspath(file))
my_loader = jinja2.ChoiceLoader([
jinja2.FileSystemLoader(os.path.join(PROJECT_ROOT, 'templates')),
web.app.jinja_loader,
])
web.app.jinja_loader = my_loader

@web.app.route("/stats")def stats():
return render_template('stats.html')

Really you can redefine index.html and change locust home page. Problem
is that there is no [easy] way to extend default index.html, so just copy
its content from source code. Then you can add {% block %} and use
index.html as a base template for your stats.html. I think developers
should add such blocks to default index.html, so it is easy to use it as
a default template for your custom pages and redefine blocks if you need.


Reply to this email directly or view it on GitHub
#224 (comment).

Thnx,
Partha saradhi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants