如何添加元关键字与django [英] How to add meta keyword with django

查看:107
本文介绍了如何添加元关键字与django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码添加元关键字 -



在view.py

 
def类别(请求,slug)
slug = slug.lower()
product_type = local_settings.CATEGORY_NAME_TO_ID @template_render(mysite / category.html get(slug,False)
如果不是product_type:
raise Http404
products = models.Product.objects.active()。filter(product_type = product_type).all()
返回{'products':产品,'slug':slug,'key':'批发ipad,ipad与视网膜显示,ipad迷你,ipad 3,ipad 2',}
/ pre>

在模板文件中 -

  {%extends base.html%} 
{%load appletrade_tags%}
{%block key%} siteTrade - {{key}} {%endblock%}
{%block title%} site Trade - {{slug}} {%endblock%}

但这并不反映。我查看来源没有关键字。



但是,标题正在反映。



你能帮我找出错误的地方吗?



编辑: strong>



base.html

  {%extendsbase。 html%} 
{%block key%} {%if page.key%} {{page.key}} {%else%} {{block.super}} {%endif%} {%endblock% }
{%block desc%} {%if page.desc%} {{page.desc}} {%else%} {{block.super}} {%endif%} {%endblock%}
{%block title%} {%if page.title%} {{page.title}} {%else%} {{block.super}} {%endif%} {%endblock%}
{ %block content%}
{%endblock%}


解决方案

您需要使用render或render_to_response将上下文传递给模板。小节对象出现在页面上?

  from django.shortcuts import render_to_response 

def category请求,slug):
slug = slug.lower()
product_type = local_settings.CATEGORY_NAME_TO_ID.get(slug,False)
如果不是product_type:
raise Http404
product = models.Product.objects.active()。filter(product_type = product_type)
context = {
'slug':slug,
'products':products,
'关键':'批发ipad,ipad与视网膜显示,ipad迷你,ipad 3,ipad 2',
}
返回render_to_response('appletrade / category.html',上下文,context_instance = RequestContext(请求) )


I am using below code to add meta keywords -

in view.py

@template_render("mysite/category.html")
def category(request, slug):
    slug = slug.lower()
    product_type = local_settings.CATEGORY_NAME_TO_ID.get(slug, False)
    if not product_type:
        raise Http404
    products = models.Product.objects.active().filter(product_type = product_type).all()
    return { 'products' : products, 'slug' : slug, 'key':'wholesale ipad, ipad with retina display, ipad mini, ipad 3, ipad 2',}

And in template file -

{% extends "base.html"%}
{%load appletrade_tags%}
{% block key %}siteTrade - {{key}}{% endblock %}
{%block title%}site Trade - {{slug}}{%endblock%}

But it's not reflecting. I have checked in view source there is no keyword.

But Yes,title is reflecting.

Can you please help me to find out where I am wrong ?

EDIT :

base.html

{% extends "base.html"%}
{% block key %}{%if page.key%}{{page.key}}{%else%}{{block.super}}{%endif%}{% endblock %}
{% block desc %}{%if page.desc%}{{page.desc}}{%else%}{{block.super}}{%endif%}{% endblock %}
{%block title%}{%if page.title%}{{page.title}}{%else%}{{block.super}}{%endif%}{%endblock%}
{%block content%}
{%endblock%}

解决方案

You need to be using either render or render_to_response to pass a context to the template. Is the slug object appearing on the page?

from django.shortcuts import render_to_response

def category(request, slug):
    slug = slug.lower()
    product_type = local_settings.CATEGORY_NAME_TO_ID.get(slug, False)
    if not product_type:
        raise Http404
    products = models.Product.objects.active().filter(product_type = product_type)
    context = {
        'slug': slug,
        'products': products,
        'key': 'wholesale ipad, ipad with retina display, ipad mini, ipad 3, ipad 2',
    }
    return render_to_response('appletrade/category.html', context, context_instance=RequestContext(request))

这篇关于如何添加元关键字与django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆