A simple django package for managing meta tags, og tags, images, and descriptions dynamically.
Project description
PAGE META
Page meta is a Django package allowing to add meta tags, og tags, images, and descriptions dynamically. Meta tags are stored in models and can be managed through Django admin (or any CMS).
Installation
pip install django-pagemeta
In settings file
INSTALLED_APPS = [
...
'pagemeta',
...
]
MIDDLEWARE = [
...
'pagemeta.middleware.MetaRequestMiddleware', # for binding meta into the request
...
]
Creating a Meta tags
- Run the server.
- Go to the Django Admin > Page_meta > Meta for pages.
- Create Meta for pages, use full absolute url in
page_url
. Also supports relative url but might varies in different domains. - To create default tags for the whole system, use
page_url
asdefault
orDEFAULT
(case insensitive)
Usage
Load the meta tags in template
In your template
<head>
...
{{ request.meta }}
...
</head>
Page titles are not rendered through request.meta. To render page title see the below example
...
<title>{{ request.meta.title|default:'Default title' }}</title>
...
OR
...
<title>{% if request.meta.title %}{{ request.meta.title }}{% else %}Title for {{ article }}{% endif %}</title>
...
Set a Custom Meta tags
If you want to set a custom meta tags for specific pages or conditions, you can reassign request.meta with an instance of Meta
.
Note: context variable can be overridden if MetaForPage for that url exists
Example code:
class MyView(TemplateView):
...
def get_context_data(self, **kwargs):
...
# adding custom meta
self.request.meta = Meta(
title='custom test',
description='custom description',
image_url='http://image_url_dot_com',
)
...
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django-pagemeta-1.0.2.tar.gz
(10.8 kB
view hashes)
Built Distribution
Close
Hashes for django_pagemeta-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e71e9ad0d49012218208e7e4b9a7cd99c33bfe85cb25f76b3b979883e8d83e94 |
|
MD5 | 0fed8b34d7566eab336a192095a561ac |
|
BLAKE2b-256 | 8ac96fef1f8f73cd9e2845d51d4a0c21d61264a1e4c39fc01cc1f2f226d81b4b |