Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mktemplate does not work with project level template directories #48

Open
haukuri opened this issue Jun 22, 2024 · 2 comments
Open

mktemplate does not work with project level template directories #48

haukuri opened this issue Jun 22, 2024 · 2 comments

Comments

@haukuri
Copy link

haukuri commented Jun 22, 2024

When trying to generate templates with the mktemplate management command in a project with a project-level template directory, the command blows up when trying to access the template_dirs attribute on an instance of django.template.engine.Engine.

File "/home/haukur/Projects/neapolitan/src/neapolitan/management/commands/mktemplate.py", line 100, in handle
    target_dir = Engine.get_default().template_dirs[0]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Engine' object has no attribute 'template_dirs'. Did you mean: 'template_loaders'?

I went digging around and found that template_dirs is an attribute of django.template.backends.base.BaseEngine.

I can only assume that there are some cases in which Engine.get_default() returns a subclass of BaseEngine instead of an instance of Engine.

I have a test project in a fork of Neapolitan that can be used to reproduce the error with

python manage.py mktemplate ice_cream.IceCream --list

I also have a branch in which I patched the mktemplate handle method to use the dirs property on Engine instead of the template_dirs property on BaseEngine if the latter is not present on the default engine. I'm not sure if that is always the correct behavior but it works on my machine (tm).

@carltongibson
Copy link
Owner

Yes, this would be an addition. I only use app template dirs, so never built for this.

Happy to take a patch adding a fallback with tests.

@jefftriplett
Copy link

I just tested this for a project-level template, and it worked great.

I did not test it for an app-level template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants