Where to put Jinja extension code?
See original GitHub issueHi
I put extension code in cookiecutter.json
{
"_extensions": ["super.SuperExtension"]
}
and I created the super/super.py
and super/__init__.py
files with:
from jinja2 import nodes
from jinja2.ext import Extension
class SuperExtension(Extension):
# a set of names that trigger the extension.
# tags = {'cache'}
def __init__(self, environment):
super(SuperExtension, self).__init__(environment)
# add the defaults to the environment
environment.extend(
keep_trailing_newline=True
)
However when I run the cookiecutter command it keeps telling me
cookiecutter.exceptions.UnknownExtension: Unable to load extension: No module named 'super'
I copied the super
directory everywhere I can think and it don’t find it.
So my question is where do I need to put the super
dir?
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Jinja - Visual Studio Marketplace
First, you will need to install Visual Studio Code 0.10 . In the command palette ( cmd-shift-p ) select Install Extension and choose...
Read more >Extensions — Jinja Documentation (3.0.x)
Jinja supports extensions that can add extra filters, tests, globals or even extend the parser. The main motivation of extensions is to move...
Read more >Visual Studio Code and Jinja templates - Stack Overflow
6 Answers 6 · Go to preferences >> settings >> type "file associations" in the search settings bar, click on "edit settings.json" ·...
Read more >How to Write a Jinja2 Extension - Ron.sh
Extending Jinja2 can be started by subclassing the jinja2.ext.Extension class and implementing the parse method. To introduce a new tag, we need ...
Read more >Primer on Jinja Templating - Real Python
Adjust Your Base Template; Extend Child Templates; Include a ... Source Code: Click here to download the source code that you'll use to ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just a quick related question
Why is it, that the cookiecutter template directory is not added to path by default or at least an
extensions
directory therein? Lets say we have this structure and I have a custom extension inmy_custom_ext.py
, that I’d like to use.I don’t want to tell my user to
export PYTHONPATH=/path/to/./extensions
or some such. They would expect that to work out of the box. Especially if the template comes from a git repository and the user would have to figure where exactly cookiecutter downloaded it to.The reason can’t be security because hooks basically already allow code execution. It can’t be a maintenance burden on the cookiecutter team, because only advanced users would write their own extensions and they’d expect that they are responsible for what they write.
if I don’t run cookiecutter yet after its installation or remove
~/.cookiecutters/my-template/
and runPYTHONPATH=~/.cookiecutters/my-template/ cookiecutter https://github.com/.../my-template
it is failing withUnable to load extension: No module named 'extensions'
. For each next run it works fine and extensions can be imported. Any thoughts?