Django for AWS: favicon, robots.txt and sitemap?

I have deployed a Django site on Elastic Beanstalk using this tutorial: https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/

But I have no idea where or how to put favicon.ico, robots.txt and sitemap.xml. Any ideas?

+3


source to share


2 answers


For favicon.ico

and, sitemap.xml

you can put them in a directory static/

and refer to them in a template with a static url. For example:.

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

      



Yours is a robots.txt

little more complicated (as with any django app). You can put it in a directory templates

and in the urls.py

following:

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

      

+1


source


To get your work files working, you can use the infrastructure django.contrib.sitemaps

: docs . Or if you have a static number of pages, just follow these steps:

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'
    )),
]

      

To favicon.ico

put it in your folder static

and use this template tag in your template:



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

      

Remember to support all devices: complete icon list

+1


source







All Articles