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

How to set a local/custom template in Email actions #126

Closed
matiskay opened this issue Mar 14, 2019 · 4 comments
Closed

How to set a local/custom template in Email actions #126

matiskay opened this issue Mar 14, 2019 · 4 comments

Comments

@matiskay
Copy link
Contributor

matiskay commented Mar 14, 2019

Hi,

I would like to know if there is way to pass a local jinja template to the actions. I'm setting a local path and absolute path in SPIDERMON_BODY_HTML_TEMPLATE but I'm getting a TemplateNotFound error.

I tried SPIDERMON_BODY_HTML_TEMPLATE = 'reports/email/monitors/result.jinja' and it worked but I would like to add my own template.

It looks like jinja2 loader only looks at /spidermon/contrib/actions/reports/templates/ folder inside spidermon package.

@matiskay matiskay changed the title How to set a local template in Email actions How to set a local/custom template in Email actions Mar 14, 2019
@rennerocha
Copy link
Collaborator

Try creating a custom action and include the path for your template inside template_paths class attribute. This should solve your problem for now, but I believe it would be a good idea to add a new setting to allow us to define a list of locations that we want the templates to be searched against.

@rennerocha
Copy link
Collaborator

rennerocha commented Jun 6, 2019

When trying to load a template that is an absolute path, Jinja2 loader didn't look at the right place, but instead it concatenates the provided absolute path to the paths loaded in the Environment.

At this moment you can not use absolute paths for Spidermon's custom templates. You need to create a custom action inherited from SendMail and define the a template_paths list as class attribute, containing the absolute location of your desired template.

After that include just the name of your template.

@rennerocha
Copy link
Collaborator

Considering that my template is located in /absolute/location/of/my/template/template_name.jinja

from spidermon.contrib.actions.email import SendEmail

class MyCustomSendEmail(SendEmail):
  template_paths = ["/absolute/location/of/my/template"]

and add to settings.py:

SPIDERMON_BODY_HTML_TEMPLATE = "template_name.jinja"

@rennerocha
Copy link
Collaborator

@matiskay Spidermon 1.10.2 allows you to set an absolute path for your custom templates.
If you find any problems, refer to this issue again.

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

No branches or pull requests

4 participants