Configuring jinja2 from within flask to use FileSystemLoader
I've been working on a flask app, which i'd like to bundle into an exe with pyinstaller. After many hours of frustrating and research I think I've come across the answer but I'm not sure how to proceed
Background
the flask app is structured like this:
/flaskapp
- routes.py
- table_func.py
- froms.py
- /static
- /css
- index.css
- /templates
page.html
page.html is using the jinja2 template engine with flask to display tables which are created and styled with pandas, it is also displaying forms that I'm using flask-WTF to create.
Its designed so that the HTML stays the same and the content changes based on the tables that are sent to the HTML using jinja2 templating like so:
<div class="block">
<div class="table1">
{{ title | safe }}
</div>
<div class = "table2">
{{ table | safe }}
</div>
</div>
<br><br>
<div class="block">
<div class="table1">
{{ title | safe }}
</div>
<div class="table2">
{{ heat | safe }}
</div>
</div>
The reason for the multiple divs being used is for layout purposes
Issue
after packaging up the flask app using pyinstall it will only return and display pages that do not use the jinja2 template system, any pages that do make use of jinja2 templates throw out a NotImplementedError: Can't perform this operation for unregistered loader type
error
So after lots of research and testing I'm pretty sure it is to do with the jinja2 template engine in flask not being supported with pyinstaller, specifically because of jinja2's use of the PackageLoader api as seen here
https://github.com/pyinstaller/pyinstaller/issues/1898
pyinstaller issue 183 seems to suggest this isn't an issue, but it still is since it isn't working]
through further digging through stack overflow and the jinja2 docs it seems like the best solution is to use jinja2's FileSystemLoader API instead of PackageLoader.
https://stackoverflow.com/questions/38642557/how-to-load-jinja-template-directly-from-filesystem
https://stackoverflow.com/questions/38617900/need-to-package-jinja2-template-for-python
http://jinja.pocoo.org/docs/2.10/api/#loaders
I'm assuming that once i convert to this it'll allow pyinstaller to package up the flask app and will stop throwing errors when trying to load a page using jinja2 templates.
But I'm not really sure how to proceed from this point, how do I tell flask to use a different loader within jinja2 when calling render_template()
I'm assuming flask has some way of configuring jinja2?
python python-3.x flask jinja2
add a comment |
I've been working on a flask app, which i'd like to bundle into an exe with pyinstaller. After many hours of frustrating and research I think I've come across the answer but I'm not sure how to proceed
Background
the flask app is structured like this:
/flaskapp
- routes.py
- table_func.py
- froms.py
- /static
- /css
- index.css
- /templates
page.html
page.html is using the jinja2 template engine with flask to display tables which are created and styled with pandas, it is also displaying forms that I'm using flask-WTF to create.
Its designed so that the HTML stays the same and the content changes based on the tables that are sent to the HTML using jinja2 templating like so:
<div class="block">
<div class="table1">
{{ title | safe }}
</div>
<div class = "table2">
{{ table | safe }}
</div>
</div>
<br><br>
<div class="block">
<div class="table1">
{{ title | safe }}
</div>
<div class="table2">
{{ heat | safe }}
</div>
</div>
The reason for the multiple divs being used is for layout purposes
Issue
after packaging up the flask app using pyinstall it will only return and display pages that do not use the jinja2 template system, any pages that do make use of jinja2 templates throw out a NotImplementedError: Can't perform this operation for unregistered loader type
error
So after lots of research and testing I'm pretty sure it is to do with the jinja2 template engine in flask not being supported with pyinstaller, specifically because of jinja2's use of the PackageLoader api as seen here
https://github.com/pyinstaller/pyinstaller/issues/1898
pyinstaller issue 183 seems to suggest this isn't an issue, but it still is since it isn't working]
through further digging through stack overflow and the jinja2 docs it seems like the best solution is to use jinja2's FileSystemLoader API instead of PackageLoader.
https://stackoverflow.com/questions/38642557/how-to-load-jinja-template-directly-from-filesystem
https://stackoverflow.com/questions/38617900/need-to-package-jinja2-template-for-python
http://jinja.pocoo.org/docs/2.10/api/#loaders
I'm assuming that once i convert to this it'll allow pyinstaller to package up the flask app and will stop throwing errors when trying to load a page using jinja2 templates.
But I'm not really sure how to proceed from this point, how do I tell flask to use a different loader within jinja2 when calling render_template()
I'm assuming flask has some way of configuring jinja2?
python python-3.x flask jinja2
Like this? SO Post. You can set thejinja_loader
on your Flask instance, like so here
– kstullich
Nov 21 '18 at 5:16
add a comment |
I've been working on a flask app, which i'd like to bundle into an exe with pyinstaller. After many hours of frustrating and research I think I've come across the answer but I'm not sure how to proceed
Background
the flask app is structured like this:
/flaskapp
- routes.py
- table_func.py
- froms.py
- /static
- /css
- index.css
- /templates
page.html
page.html is using the jinja2 template engine with flask to display tables which are created and styled with pandas, it is also displaying forms that I'm using flask-WTF to create.
Its designed so that the HTML stays the same and the content changes based on the tables that are sent to the HTML using jinja2 templating like so:
<div class="block">
<div class="table1">
{{ title | safe }}
</div>
<div class = "table2">
{{ table | safe }}
</div>
</div>
<br><br>
<div class="block">
<div class="table1">
{{ title | safe }}
</div>
<div class="table2">
{{ heat | safe }}
</div>
</div>
The reason for the multiple divs being used is for layout purposes
Issue
after packaging up the flask app using pyinstall it will only return and display pages that do not use the jinja2 template system, any pages that do make use of jinja2 templates throw out a NotImplementedError: Can't perform this operation for unregistered loader type
error
So after lots of research and testing I'm pretty sure it is to do with the jinja2 template engine in flask not being supported with pyinstaller, specifically because of jinja2's use of the PackageLoader api as seen here
https://github.com/pyinstaller/pyinstaller/issues/1898
pyinstaller issue 183 seems to suggest this isn't an issue, but it still is since it isn't working]
through further digging through stack overflow and the jinja2 docs it seems like the best solution is to use jinja2's FileSystemLoader API instead of PackageLoader.
https://stackoverflow.com/questions/38642557/how-to-load-jinja-template-directly-from-filesystem
https://stackoverflow.com/questions/38617900/need-to-package-jinja2-template-for-python
http://jinja.pocoo.org/docs/2.10/api/#loaders
I'm assuming that once i convert to this it'll allow pyinstaller to package up the flask app and will stop throwing errors when trying to load a page using jinja2 templates.
But I'm not really sure how to proceed from this point, how do I tell flask to use a different loader within jinja2 when calling render_template()
I'm assuming flask has some way of configuring jinja2?
python python-3.x flask jinja2
I've been working on a flask app, which i'd like to bundle into an exe with pyinstaller. After many hours of frustrating and research I think I've come across the answer but I'm not sure how to proceed
Background
the flask app is structured like this:
/flaskapp
- routes.py
- table_func.py
- froms.py
- /static
- /css
- index.css
- /templates
page.html
page.html is using the jinja2 template engine with flask to display tables which are created and styled with pandas, it is also displaying forms that I'm using flask-WTF to create.
Its designed so that the HTML stays the same and the content changes based on the tables that are sent to the HTML using jinja2 templating like so:
<div class="block">
<div class="table1">
{{ title | safe }}
</div>
<div class = "table2">
{{ table | safe }}
</div>
</div>
<br><br>
<div class="block">
<div class="table1">
{{ title | safe }}
</div>
<div class="table2">
{{ heat | safe }}
</div>
</div>
The reason for the multiple divs being used is for layout purposes
Issue
after packaging up the flask app using pyinstall it will only return and display pages that do not use the jinja2 template system, any pages that do make use of jinja2 templates throw out a NotImplementedError: Can't perform this operation for unregistered loader type
error
So after lots of research and testing I'm pretty sure it is to do with the jinja2 template engine in flask not being supported with pyinstaller, specifically because of jinja2's use of the PackageLoader api as seen here
https://github.com/pyinstaller/pyinstaller/issues/1898
pyinstaller issue 183 seems to suggest this isn't an issue, but it still is since it isn't working]
through further digging through stack overflow and the jinja2 docs it seems like the best solution is to use jinja2's FileSystemLoader API instead of PackageLoader.
https://stackoverflow.com/questions/38642557/how-to-load-jinja-template-directly-from-filesystem
https://stackoverflow.com/questions/38617900/need-to-package-jinja2-template-for-python
http://jinja.pocoo.org/docs/2.10/api/#loaders
I'm assuming that once i convert to this it'll allow pyinstaller to package up the flask app and will stop throwing errors when trying to load a page using jinja2 templates.
But I'm not really sure how to proceed from this point, how do I tell flask to use a different loader within jinja2 when calling render_template()
I'm assuming flask has some way of configuring jinja2?
python python-3.x flask jinja2
python python-3.x flask jinja2
asked Nov 21 '18 at 4:25
JisketJisket
203
203
Like this? SO Post. You can set thejinja_loader
on your Flask instance, like so here
– kstullich
Nov 21 '18 at 5:16
add a comment |
Like this? SO Post. You can set thejinja_loader
on your Flask instance, like so here
– kstullich
Nov 21 '18 at 5:16
Like this? SO Post. You can set the
jinja_loader
on your Flask instance, like so here– kstullich
Nov 21 '18 at 5:16
Like this? SO Post. You can set the
jinja_loader
on your Flask instance, like so here– kstullich
Nov 21 '18 at 5:16
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405248%2fconfiguring-jinja2-from-within-flask-to-use-filesystemloader%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405248%2fconfiguring-jinja2-from-within-flask-to-use-filesystemloader%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Like this? SO Post. You can set the
jinja_loader
on your Flask instance, like so here– kstullich
Nov 21 '18 at 5:16