Specifying an Alternative Path for a Haystack Template

Haystack documentation states that :

Also provided was use_template=True in the text box. This allows us to use a data template (rather than concatenation with errors) to create a document that the search engine will index. You need to create a new template inside your template directory called search/indexes/myapp/note_text.txt

Unfortunately, there is no information on what to do if you want to have a named template.

Can I specify a path to a haystack document template?

+5
source share
1 answer

Come on, I've been looking for this for a week.

It is listed in the SearchField API SearchField , which is a superclass of the actual fields in the search index.

SearchField.template_name

Allows you to override the name of the template that will be used in the preparation of the data. By default, data templates for fields are located within your TEMPLATE_DIRS under a road similar to search/indexes/{app_label}/{model_name}_{field_name}.txt . This allows you to override this path (although still within TEMPLATE_DIRS ).

Example:

 bio = CharField(use_template=True, template_name='myapp/data/bio.txt') 

You can also provide a list of templates, since loader.select_template is used under the hood.

Example:

 bio = CharField(use_template=True, template_name=['myapp/data/bio.txt', 'myapp/bio.txt', 'bio.txt']) 
+7
source

All Articles