Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django returning HTTP 301?

I have a django view that returns HTTP 301 on a curl request:

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 

I can't get the page's content from curl. However, if I visit the page with a browser, I see the content as expected.

Any ideas?

Thanks, Pete

like image 398
slypete Avatar asked Oct 16 '09 19:10

slypete


People also ask

Why am I getting 301 moved permanently Django?

Django comes with an optional redirects application. It lets you store redirects in a database and handles the redirecting for you. It uses the HTTP response status code 301 Moved Permanently by default.

How to return redirect back in Django?

Just call redirect() with a URL in your view. It will return a HttpResponseRedirect class, which you then return from your view. Assuming this is the main urls.py of your Django project, the URL /redirect/ now redirects to /redirect-success/ .

What is permanent redirect in Django?

Permanent redirects are for when resource URLs change.


2 Answers

You are probably requesting the URL without a trailing slash, and have APPEND_SLASH set to True (the default) in settings.py, so Django is redirecting to the URL including a slash.

like image 104
Daniel Roseman Avatar answered Oct 12 '22 10:10

Daniel Roseman


My problem was PREPEND_WWW, when using it in localhost it returns a 301 error, I just created a local settings file and set it PREPEND_WWW = False

like image 21
AbeEstrada Avatar answered Oct 12 '22 12:10

AbeEstrada