1

Pass HTML file for getting all HTML content as a string into jinja2.Markup, like

content = jinja2.Markup('python/pythonIntro.html') // I know it is wrong...

Here I need to pass file name and markup all contents. How should I do?

1 Answer 1

1

FYI, You can use this code for find required file from you environment and also pass path of file which return all contents of file.

from jinja2 import Markup, PackageLoader, Environment

def include_file(name):
    #env = jinja2.environment
    return Markup(loader.get_source(env, name)[0])

loader = PackageLoader(__name__, '')
env = Environment(loader=loader)
env.globals['include_file'] = include_file

print env.get_template('templates/<file.ext>').render() # as per address of file structure
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.