I am trying to implement Django queryset in jQuery/javascript. I was able to get the list of all users but i could not get the users profile picture. Username display, but users image do not display as an image, it display as a text ( John). How do i get the users profile picture for each user? This is what i tried:
class Profile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL,on_delete=models.CASCADE,blank=True,null=True)
profile_pic = models.ImageField(upload_to='ProfilePicture/', default="ProfilePicture/user-img.png", blank=True)
def home(request):
all_img = Profile.objects.all()
context = {
'all_img': all_img,
}
$(function() {
var availableTags = [
{% for user in all_img %}{% if user.profile_pic %}
"<img src='{{ user.profile_pic.url }}'>" + "{{user|safe}}",
{% endif %}{% endfor %}
];
$(".autocomplete").autocomplete({
source: availableTags,
})
});
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')