为站点或特定URL中的对象添加通用SEO字段

redsolutioncms.django-seo的Python项目详细描述


在管理中注册的任何模型的对象或指定url的seo字段。

安装:

  1. seo作为Django项目中settings.pyINSTALLED_APPS的最后一项。

  2. 同步数据库:

    ./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 %}

redsolution cms分类器:

Content plugins

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
如何表示1。。Java中的n关系   java在安卓应用程序中添加polaris viewer   Java字符串::replaceAll仅替换第一个出现(可能不正确的正则表达式)   java Tomcat/JBoss部署后脚本   如何在Heroku Java应用程序中运行发出web请求的周期进程   java如何以纳秒为单位证明算法的时间   Solaris上的java自定义ListCellRenderer(使用jre5)   java试图为我的播放器类测试块实现播放器重力(RealtutsGml平台教程)   c#消耗一个。带有java的net web服务未显示预期结果   java在KOI8\R中检索html   基于java图形的搜索与基于随机的搜索   java如何检查安卓设备上的可用空间?在SD卡上?