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
Metadata
Release files for django-ogp-view 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_ogp_view-1.1.0.tar.gz | 15.0 kB | Without provenance | Details for django_ogp_view-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_ogp_view-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for django_ogp_view-1.1.0-py3-none-any.whl |
Total release size: 35.1 kB
Release files / django_ogp_view-1.1.0.tar.gz
| Download URL | django_ogp_view-1.1.0.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b740bc62497134fa81b289f97285ac445a00229d807865327f3810126a48f024
|
|
BLAKE2b-256 checksum How to use checksums |
8ae13e4f7b84f4df0ae5ad863ad6af1cb4124465c5bdd49254c7d6f307df0993
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / django_ogp_view-1.1.0-py3-none-any.whl
| Download URL | django_ogp_view-1.1.0-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
617c4dc688feafdb4775be52a719761025123dc62fc4cab5d709ac56cd2a3622
|
|
BLAKE2b-256 checksum How to use checksums |
9133875c5c5924e3d6e291578a9bcd19ee21312c0bcd7b3afafe9bfa14a40c57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for django-ogp-view 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.