.. _introduction-tutorial: ============================== django-seo2 Framework Tutorial ============================== Adding SEO to your Django site is easy, you need to do two things: - Define which metadata fields you need - Add the output to your templates Before we start --------------- This tutorial assumes you already know how to use Django, and that you have a site with some apps already up and running. It assumes you have installed the library somewhere where python can get it, and that you've added ``djangoseo`` to your ``INSTALLED_APPS`` setting. Metadata definition ------------------- You can define which fields appear in your metadata by creating a class that subclasses ``seo.Metadata``. For example, create a new file called ``seo.py`` in an app on your site: .. code-block:: python from djangoseo import seo class MyMetadata(seo.Metadata): title = seo.Tag(head=True, max_length=68) description = seo.MetaTag(max_length=155) keywords = seo.KeywordTag() heading = seo.Tag(name="h1") Done! The above definition outlines four fields: - A ``
I like gypsy Jazz!
.. note:: Make sure you have ``"django.core.context_processors.request"`` listed in your site's ``TEMPLATE_CONTEXT_PROCESSORS`` setting. This provides ``{% get_metadata %}`` with the current path, allowing it to automatically select the relevant metadata. Seeing it in action ------------------- Using the admin site, add some new metadata, attaching it to a (valid) path of your choice. Open up your browser and visit the path, to hopefully see something like this in the page source: .. code-block:: htmlI like gypsy Jazz!