Configuring jinja2 from within flask to use FileSystemLoader












0















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?










share|improve this question























  • Like this? SO Post. You can set the jinja_loader on your Flask instance, like so here

    – kstullich
    Nov 21 '18 at 5:16


















0















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?










share|improve this question























  • Like this? SO Post. You can set the jinja_loader on your Flask instance, like so here

    – kstullich
    Nov 21 '18 at 5:16
















0












0








0








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 4:25









JisketJisket

203




203













  • 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



















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














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
});


}
});














draft saved

draft discarded


















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
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?