mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-13 03:33:55 +00:00
33 lines
990 B
Python
33 lines
990 B
Python
"""
|
|
Jinja2 rendering utils, used to generate new strategy and configurations.
|
|
"""
|
|
|
|
|
|
from typing import Dict, Optional
|
|
|
|
|
|
def render_template(templatefile: str, arguments: Dict) -> str:
|
|
|
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
|
|
|
env = Environment(
|
|
loader=PackageLoader('freqtrade', 'templates'),
|
|
autoescape=select_autoescape(['html', 'xml'])
|
|
)
|
|
template = env.get_template(templatefile)
|
|
return template.render(**arguments)
|
|
|
|
|
|
def render_template_with_fallback(templatefile: str, templatefallbackfile: str,
|
|
arguments: Optional[Dict] = None) -> str:
|
|
"""
|
|
Use templatefile if possible, otherwise fall back to templatefallbackfile
|
|
"""
|
|
from jinja2.exceptions import TemplateNotFound
|
|
if arguments is None:
|
|
arguments = {}
|
|
try:
|
|
return render_template(templatefile, arguments)
|
|
except TemplateNotFound:
|
|
return render_template(templatefallbackfile, arguments)
|