¿Django devuelve HTTP 301?


Tengo una vista django que devuelve HTTP 301 en una solicitud curl:

grapefruit:~ pete$ curl -I http://someurl
HTTP/1.1 301 MOVED PERMANENTLY
Date: Fri, 16 Oct 2009 19:01:08 GMT
Server: Apache/2.2.9 (Win32) mod_wsgi/2.5 Python/2.6.2 PHP/5.2.6
Location: http://someurl
Content-Type: text/html; charset=utf-8

No puedo obtener el contenido de la página de curl. Sin embargo, si visito la página con un navegador, veo el contenido como se espera.

¿Alguna idea?

Gracias, Pete

Author: slypete, 2009-10-16

3 answers

Probablemente está solicitando la URL sin una barra diagonal final, y tiene APPEND_SLASH establecido en True (el valor predeterminado) en settings.py, por lo que Django está redirigiendo a la URL incluyendo una barra diagonal.

 131
Author: Daniel Roseman,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-10-16 19:12:31

Mi problema fue PREPEND_WWW, al usarlo en localhost devuelve un error 301, acabo de crear un archivo de configuración local y lo establecí PREPEND_WWW = False

 4
Author: AbeEstrada,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2010-11-24 17:00:56

En mi caso, comentar el SecurityMiddleware en el archivo settings.py hizo el truco. Tengo que decir que esto solo sucede cuando se ejecuta el comando runserver (aka. al probar). Con Apache no cae en el bucle de redirección.

 1
Author: Hassek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-27 14:16:24