S
S
softshape2015-10-05 05:47:16
Django
softshape, 2015-10-05 05:47:16

How to make DisallowedHost error 400 instead of 500 in Django?

In Django 1.8, the DisallowedHost error should already return a 400 error instead of a 500 error. However, my mailbox is still full of such letters every day -
DisallowedHost: Invalid HTTP_HOST header: 'www.cirk.irk.ru'. You may need to add u'www.cirk.irk.ru' to ALLOWED_HOSTS.
The error is caused by GoogleBot. Logging is configured like this:

'django.security.DisallowedHost': {
          'handlers': ['null'],
          'propagate': False,
        },

But all the same errors in letters climb. How to make them be 400x instead of 500x?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery Ryaboshapko, 2015-10-05
@softshape

Try to make a 301 ("permanent") redirect from www.cirk.irk.ru to cirk.irk.ru using nginx. In theory, this should discourage Googlebot. In addition, you will definitely stop receiving such emails, because requests for a non-existent domain will not reach Django.

R
Rostislav Grigoriev, 2015-10-05
@crazyzubr

It's written

You may need to add u'www.cirk.irk.ru' to ALLOWED_HOSTS

Add this domain to the ALLOWED_HOSTS list.
ALLOWED_HOSTS documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question