defunkt / pystache

Mustache in Python
http://mustache.github.com/
MIT License
1.31k stars 308 forks source link

Render template from database causing TemplateNotFoundError #198

Closed bachirelkhoury closed 5 years ago

bachirelkhoury commented 5 years ago

I am rendering a template loaded from a database using Python3.7 on Ubuntu 18.04.

Getting this error: pystache.common.TemplateNotFoundError: File 'ict.mustache' not found in dirs: ['.']

    template_data = {
            'id1': uuid.uuid4(),
            'id2': uuid.uuid4(),
            'value1': 'someValue1',
            'value2': 'someValue2'
        }

rendered_data = pystache.render(template_from_db, template_data)

I'm not sure why is it even looking for a mustache file, I'm not using any.

Also note that this same app is working correctly in similar dev environment on Mac. What's that ict.mustache file?

bachirelkhoury commented 5 years ago

Turns out it's to do with jsonb in the postgresql database. It is allowing to store a plain string, instead of a valid json. Dirty data (plain strings) were working, but on server we have valid jsonb which wich was causing the issue. All sorted by:

template_string = json.dumps(template_from_db)
rendered_data = pystache.render(template_string, template_data)