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%}
Here is a way to automate keywords for your django site. I don't like manually entering things anyways.
Here's a function to read your template file and count primary words, and return the list of the words used in the page.
Place meta_gen.py in your main project folder. Then add these pieces to each of your views.py files.
And lastly in your main template base.html you place the meta tag for keywords.
And that's it. All pages that inherit the base template and have the views.py code will insert keywords meta tags with words that repeat on your pages.
I realize that this can be improved upon and optimized. Speed isn't a concern for me. So input is welcome.
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?