Open Graph Protocol for Django
Project description
django-ogp-view
ViewクラスにOGP (The Open Graph protocol)を適応させるライブラリです。
本ライブラリのViewMixinを継承させることで、ogp metaタグの実装が簡略化できます。
画面ごとにカスタマイズすることもできます。
SEO (Search Engine Optimization)対策に最適です。
導入
- ライブラリをインストールする。
pip install django-ogp-view or pip install git+https://github.com/taogya/DjangoOgpView.git
- settings.pyに以下を追加する。
INSTALLED_APPS = [ : 'django_ogp' ] OGP_SITE_PROPERTY_MODEL = 'django_ogp.OgpSiteProperty' OGP_LOCALE_MASTER_MODEL = 'django_ogp.OgpLocaleMaster' OGP_MIMETYPE_MASTER_MODEL = 'django_ogp.OgpMimeTypeMaster'
- migrateを行う。
python manage.py makemigrations python manage.py migrate
- OGP用のプロパティを設定する。
- OgpSiteProperty
サイト内共通のプロパティ。 - OgpBasicProperty
ページごとのプロパティ。 - OgpCustomProperty
カスタムプロパティ。
JSONで指定する。
JSONについて, keyはpropertyの名称, valueはcontentの値で指定する。
- OgpSiteProperty
- ViewにOgpViewMixinを継承し, 割り当てるプロパティのレコードを割り当てる。
from django.views import View from django_ogp.view import OgpViewMixin from django_ogp.models import OgpBasicProperty class YourView(View, OgpViewMixin): ogp = OgpBasicProperty.objects.first() :
- 以下のようにhtmlファイルにdjango_ogp用のタグを追加する。
{% load django_ogp %} <!DOCTYPE html> <html lang="en" prefix="{{ view.ogp_global_prefix }}"> <head prefix="{{ view.ogp_prefix }}"> {% add_ogp_meta %} :
Models
補足
- マイグレーションファイル にはマスターデータ自動生成スクリプトが含まれています。
不要なデータがありましたら, 管理者画面にて削除するかマイグレーションファイルを修正してください。 - 以下のモデルは
swappableなモデルです。- OgpSiteProperty
- OgpLocaleMaster
- OgpMimeTypeMaster
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
django_ogp_view-1.1.0.tar.gz
(15.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_ogp_view-1.1.0.tar.gz.
File metadata
- Download URL: django_ogp_view-1.1.0.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b740bc62497134fa81b289f97285ac445a00229d807865327f3810126a48f024
|
|
| MD5 |
5448694a8c5805d4f7b37433f673a586
|
|
| BLAKE2b-256 |
8ae13e4f7b84f4df0ae5ad863ad6af1cb4124465c5bdd49254c7d6f307df0993
|
File details
Details for the file django_ogp_view-1.1.0-py3-none-any.whl.
File metadata
- Download URL: django_ogp_view-1.1.0-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
617c4dc688feafdb4775be52a719761025123dc62fc4cab5d709ac56cd2a3622
|
|
| MD5 |
ae0bde49d47b5695198f4684e9aa10e5
|
|
| BLAKE2b-256 |
9133875c5c5924e3d6e291578a9bcd19ee21312c0bcd7b3afafe9bfa14a40c57
|