Closed kamuri-chan-alt closed 3 years ago
@kamuri-chan-alt you must rewrite _metadata
as
_metadata = {
'title': 'title',
'image': 'get_meta_image',
}
see example here: https://django-meta.readthedocs.io/en/latest/models.html?highlight=get_meta_image#usage
with your code, the value if self.image
(which is an object) is used, but a string is expected
Thank you, but now it's raising another error:
Request Method: GET http://127.0.0.1:8000/jojofag 3.1.2 ImproperlyConfigured META_SITE_PROTOCOL is not set
I know it's related to settings.SITE_PROTOCOL, but adding it to settings.py in mysite don't seems to work. Sorry, I don't really have much experience with Django.
you should set META_SITE_PROTOCOL
in project settings.py
file
Thank you for all the help, I really appreciate it.
Now there's only (at least I hope) one last thing: only the meta description is showing on the page.
result:
<head prefix="og: http://ogp.me/ns#">
<title>bump of chicken</title>
<meta name="description" content="News">
</head>
html:
<html>
{% load meta %}
<head {% meta_namespaces %}>
<title>{{post.title}}</title>
{% include "meta/meta.html" %}
</head>
views.py:
def single_slug(request, single_slug):
news = [p.post_slug for p in News.objects.all()]
if single_slug in news:
this_post = News.objects.get(post_slug=single_slug)
meta = this_post.as_meta()
return render(request=request,
template_name='main/posts.html',
context={'post': this_post, 'meta': meta
})
models.py:
class News(ModelMeta, models.Model):
title = models.CharField(max_length=200)
content = RichTextUploadingField()
datetime = models.DateTimeField('published date')
image = models.ImageField(upload_to="images", blank=False)
post_slug = AutoSlugField(populate_from='title')
category = "Notícia"
_metadata = {
'title': 'title',
'description': 'category',
'image': 'get_meta_image',
'url': 'post_slug',
}
def __str__(self):
return self.título
def get_meta_image(self):
if self.image:
return self.image.url
@kamuri-chan-alt have you set the META_USE_<FOO>_PROPERTIES = True
in the project settings?
@yakky i've solved it two days after the comment but couldn't access this account in the meantime. All working fine, thank you for all the help.
I'm trying to add the tags to a website, but it's showing this error and I don't know what to do.
My models.py
I'm using Python 3.8 and Django 3.1.2
Traceback:
Thanks.