[Django]-Django to AWS: favicon, robots.txt and sitemap?

1👍

For the favicon.ico and sitemap.xml you can put them in the static/ directory and refer to them in the template with the static URL. E.g.:

<link rel="shortcut icon" type="image/png" href="{{STATIC_URL}}/favicon.ico"/>

Your robots.txt is a bit harder (as with any django app). You can drop it into the templates directory and in your urls.py have the following:

urlpatterns = patterns('',
    ...
    (r'^robots\.txt$', TemplateView.as_view(template_name='robots.txt', content_type='text/plain')),
)
👤Ewan

1👍

To get your sitemaps working, you can use a django.contrib.sitemaps framework: docs. Or if you have a static amount of pages just do like this:

urlpatterns = [
    # your robots.txt (and/or humans.txt) file:
    url(r'^robot\.txt$', TemplateView.as_view(
        template_name='txt/robots.txt',
        content_type='text/plain'
    )),
    # your static sitemap:
    url(r'^crossdomain\.xml$', TemplateView.as_view(
        template_name='txt/sitemap.xml',
        content_type='application/xml'
    )),
]

For the favicon.ico place it inside your static folder and use this template tag in your template:

<link rel="icon" href="{% static 'path/to/favicon.ico' %}" sizes="...">

Do not forget to support all of the devices: full list of favicons

Leave a comment