{ "info": { "author": "(the author)", "author_email": "mdilligaf@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "\nDjango hreflang\n---------------------------------\n\nProviding hreflang information for your website is recommended by Google. If you are using i18n urls, this Django app can add this hreflang information automatically in one of several ways.\n\nFor more information about hreflang, have a look at https://support.google.com/webmasters/answer/189077?hl=en\n\nInstallation & Configuration:\n-----------------------------\n\nThis assumes that you are using internationalization for your URL patterns, as described at https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#module-django.conf.urls.i18n\n\nFirst install the package::\n\n pip install django_hreflang\n\nUse version django_hreflang==1.7 for django version inferior to 2.0.\n\nYou may need to take *zero or one* of these steps:\n\n- If you want to use the html tag, add ``hreflang`` to your ``INSTALLED_APPS``\n- If you want to use the middleware, add ``hreflang.AddHreflangToResponse`` to your ``MIDDLEWARE_CLASSES``\n\nIf you have other middleware that changes the Files header, that should be okay if it doesn't overwrite previous headers. You may want to add hreflang as the first middleware when in doubt.\n\nHow to use\n---------------------------------\n\nhreflang information can, in general, be provided in three ways: in the html files's
, in the http Files header or through a sitemap. This package supports the first two.\n\nWhich way should I use?\n=================================\n\nMy personal preference is using the HTML links in a special block in the base template. If there are any special documents (e.g. pdf) use the ``hreflang_headers`` function. This allows per-page control with minimal effort (unless you serve mostly special documents).\n\nHTML (template tags)\n=================================\n\nTo include the links in the , follow this minimal example::\n\n {% load hreflang %}\n \n {% hreflang_tags %}\n \n\n(hreflang must be in installed apps.)\n\nResponse header (manually)\n=================================\n\nThe template tag method works great for normal files. But if you have special files (e.g. pdf) with multiple versions, you can use the response's file header by::\n\n from hreflang import hreflang_headers\n def your_view(request):\n response = your_code()\n return hreflang_headers(response)\n\nwhich will take care of things.\n\nResponse header (middleware)\n=================================\n\nA more automatic way that captures all kinds of files is to use a middleware. All you have to do is add ``hreflang.AddHreflangToResponse`` to your ``MIDDLEWARE_CLASSES``. You don't need to use ``hreflang_headers`` or ``{% hreflang_tags %}``. This will apply to all responses, it can not be turned on or off for individual responses.\n\n\nUseful extra template tags\n=================================\n\nFor convenience, some more template tags are included.\n\nTo obtain a link to the current document in another language, use::\n\n {% translate_url 'en' %}\n\nTo obtain a link to a specified view, use::\n\n {% translate_url 'en' view_name='namespace:name' %}\n\nTo get a list of