-1

I've created a custom User model based on AbstractUser model. How can I find the right path to my thumbnail to use in a template file ?

models.py

class User(AbstractUser):
     photo = FilerImageField(related_name='profile_photo', null=True, on_delete=models.SET_NULL)

home.html

{% extends "base.html" %}
{% load thumbnail %}

{% block content %}

{% thumbnail user.photo 250x250 crop %}
          {% thumbnail user.photo 250x250 crop %} #
{% endblock %}
TemplateSyntaxError
Exception Value:    
Variable 'user.photo' is an invalid source.
ns68
  • 9
  • 1
  • 1

1 Answers1

0

Try this one in template if you are using sorl-thumbnail

{% thumbnail user.photo "250x250" crop="center" as im %}
    <img src="{{ im.url }}" width="{{ im.width }}" height="{{ im.height }}">
{% endthumbnail %}

If you are using easy thumbnail use below code in template.html

{% load thumbnail %}
<img src="{% thumbnail profile.photo 50x50 crop %}" alt="" />

If you are using django-filer don't need to be in template thumbnail tag

{% load thumbnail %}
{% thumbnail user.photo 250x250 crop %}
Pavan kumar
  • 478
  • 3
  • 16
  • {% thumbnail . 100x100 crop %} works well. My question was how to find the right source if my User model inherits from AbstractUser class ? In my case {% thumbnail user.photo 100x100 crop %} doesn't work – ns68 Jun 25 '20 at 15:51
  • Try request.user.photo – Pavan kumar Jun 25 '20 at 15:55