Задача: Сделать добавление nofollow ко всем внешним ссылкам. Решение: Сделаем через middleware class NofollowLinkMiddleware(object): »’ Adds nofolow to external links»’ def __init__(self): self.extlinks = re.compile(r»'<a (?P[^>]*http.?://)»’) def process_response(self, request, response): if («text» in response[‘Content-Type’]): response.content = self.extlinks.sub(‘<a rel=»nofollow» g’,response.content) return response else: return response
Posts Tagged: Django-cms
Caught AttributeError while rendering: type object ‘Category’ has no attribute ‘_mptt_meta’
Django-cms 2.1.3. При открытии одной из страниц получал такую ошибку Caught AttributeError while rendering: type object ‘Category’ has no attribute ‘_mptt_meta’ Проблема оказалась из за несоответствий версий Zinnia, у меня была “0.9.dev “, а на сервере просто “0.9”. Решение оказалось следующим: 1) в терминале переходим в каталог с проектом (там где файл manage.py) 2) выполняем… Read more »
Django-cms: Поиск в Django-cms
Простейший способ по поиску во внутренних страницах в Django-cms: from cms.models.pagemodel import Page found_entries=Page.objects.search(‘test’) В Django шаблоне теперь пишем: {%if found_entries %} Query was found in pages: {% for one in found_entries %} {{ one.get_title }} {%endfor%} {% else %} Query was not found {% endif %}
Django-CMS и SEO
Встал вопрос как быть с SEO. Точнее с title, meta description, meta keywords. Как оказалось всё это подключается очень просто: http://docs.django-cms.org/en/2.1.3/getting_started/configuration.html#cms-seo-fields Точнее в settings.py указываем: CMS_SEO_FIELDS=True А потом в шаблоне добавляем: {% load cms_tags %} <head> <title>{% page_attribute page_title %}</title> <meta name=»description» content=»{% page_attribute meta_description %}»/> <meta name=»keywords» content=»{% page_attribute meta_keywords %}»/> … … </head>
Django-CMS: Разница между block, placeholder, variable?
Какая разница между block, placeholder, variable? Этот вопрос я задал в официальной группе проекта: What the main difference between block, placeholder, variable? I can write {% block content %}{% endblock%}, {%placeholder content%} {%endplaceholder%}, or {{content}}. But i want to know right way И вот ответ: A block is a Django specific thing. It comes with… Read more »
Django-CMS: Какая разница между application, plugin, snippet?
Официальный ответ с группы Django-cms: A snippet is just any piece of text. You can define them in your Django admin. Plugins are pieces of django-cms code (that you can write yourself) that have a template and that can add any variables to the context for that template. You could for example create a cms… Read more »
Свежие комментарии