Skip to content

mktemplate does not work with project level template directories #48

Description

@haukuri

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions