How can I use meta tags with my images?
I have a django blog with witch I post many text messages and image dynamically. Actually I 'm trying to go to facebook, share my posts. I put the django meta tags correctly, so I get the post title, the post content, but I can't get the post image. How can I do this?
I have models.py:
class Evento(models.Model):
nome = models.CharField(max_length=200, null=False, blank=False)
apresentacao = models.TextField(null=False, blank=False)
foto = CloudinaryField('foto', null=True, blank=True)
created_date = models.DateTimeField(
default=timezone.now)
published_date = models.DateTimeField(
blank=True, null=True)
def publish(self):
self.published_date = timezone.now()
self.save()
def __str__(self):
return self.nome
def get_absolute_url(self):
#return reverse("detalhe", kwargs={"pk": self.pk})
return "/post/%s" %(self.pk)
views.py:
def index(request):
posts = Evento.objects.filter(published_date__lte=timezone.now()).order_by('-published_date')
return render(request, 'core/index.html', {'posts': posts})
def post_detail(request, pk):
post = get_object_or_404(Evento, pk=pk)
Evento.objects.get(pk=pk)
return render(request, 'core/post_detail.html', {'post': post})
and post_detail.html:
<div class="fb-share-button" data-href="{{ request.build_absolute_uri }}" data-layout="button_count" data-size="large" data-mobile-iframe="true"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&src=sdkpreparse">Compartilhar</a></div>
<div class="post">
with meta tags in base.html:
<meta property="fb:app_id" content="xxxxx">
<meta property="fb:admins" content="yyyy">
<meta property="og:url" content="{{ request.build_absolute_uri }}"/>
<meta property="og:title" content="{{ post.nome }}">
<meta property="og:description" content="{{ post.apresentacao }}"/>
<meta property="og:image" content="{{ cloudinary post.foto }}"/>
-
Official comment
Hi Victor,
Thanks for reaching out.
I see that Evento object includes a CloudinaryField so to render an image from it you can use -
{% cloudinary post.image width=150 effect="sepia" %} (or any other transformations, of course).
Don't forget to include {% load cloudinary %} in the HTML
Let me know how it goes!
Best,
Maor
Post is closed for comments.
Comments
1 comment