为站点或特定URL中的对象添加通用SEO字段
redsolutioncms.django-seo的Python项目详细描述
在管理中注册的任何模型的对象或指定url的seo字段。
安装:
将seo作为Django项目中settings.py中INSTALLED_APPS的最后一项。
同步数据库:
./manage.py syncdb
用法:
在设置中。py:
添加要重写的ModelAdmins的名称:
SEO_FOR_MODELS = [ '<app>.models.<Model>', ]
在模板中:
首先,在每个要使用的模板中加载seo_标记:
{% load seo_tags %}
- 使用:
- {%seo<;title | keywords | description>;[对于<;object>;]%}
- 或:
- {%seo<;title keywords description>;[对于<;object>;]作为<;variable>;%} {{<;变量>;}
示例:
settings.py:
INSTALLED_APPS = ( ... 'app', ... 'seo', ) SEO_FOR_MODELS = [ 'app.models.Object', 'app.models.Another', ]
templates/object.html:
{% load seo_tags %} <html> <head> <meta name="description" content="{% seo description for object %}" /> <meta name="keywords" content="{% seo keywords for object %}" /> <title>{% seo title for object %}</title> </head> <body> {{ object.content }} <h1>{% seo title for object as seo_title %}{{ seo_title }}</h1> </body> </html>
如果使用extend
templates/base.html:
<html> <head> <meta name="description" content="{% block description %}{% seo description %}{% endblock %}" /> <meta name="keywords" content="{% block keywords %}{% seo keywords %}{% endblock %}" /> <title>{% block title %}{% seo title %}{% endblock %}</title> </head> <body> {% block content %}{% endblock %} </body> </html>
templates/object.html:
{% load seo_tags %} {% block description %}{% seo description for object %}{% endblock %} {% block keywords %}{% seo keywords for object %}{% endblock %} {% block title %}{% seo title for object %}{% endblock %} {% block content %} {{ object.content }} {% endblock %}
templates/another.html:
{% load seo_tags %} {% block description %}{% seo description for another %}{% endblock %} {% block keywords %}{% seo keywords for another %}{% endblock %} {% block title %}{% seo title for another %}{% endblock %} {% block content %} {{ another.content }} {% endblock %}