Search code examples
odooodoo-12qweb

Odoo employee image is not been showed on website template


I'm trying to show the employee's picture (fields: hr_employee.image) on a website template. But the template just show the default picture for employees instead of the loaded image.

I tried this:

<span t-field="employee.image" t-options="{'widget': 'image', 'style': 'height:200px;width:200px;'}"/>

And also, tried this:

<div t-field="employee.image" t-options="{'widget': 'image', 'style': 'height:200px;width:200px;'}"/>

And this:

<img t-field="employee.image" t-options="{'widget': 'image', 'style': 'height:200px;width:200px;'}"/>

Template just show this:

Template


Solution

  • I'm afraid accessing images isn't as simple as that since you need sudo access to get them. If you're accessing the built-in employee module then the base model already provides this sudo access for you. Instead use the following:

    <img t-att-src="image_data_uri(employee.image_1920)" style="max-height:85pt;max-width:90%"/>
    

    The 1920 refers to the image's size. You can also use employee.image_1024, employee.image_512, employee.image_256 or employee.image_128

    If you're trying to access images from your own custom module then you'll need to update the .py file to access the image and provide its public url.