[Solved]-Why does django return 301 and 302 as server response codes after a user logs in and a flatpage is displayed?

10👍

I can’t see your url pattern for the home view. But it’s probably the missing slash which makes django send out a auto-redirect:

https://docs.djangoproject.com/en/dev/ref/settings/#append-slash

Is my web client sending the request underling the fourth line? How
does it know to do this?

Yes, Status code 301 in line 3 tells the browser ‘the page you requested moved to another url x’. And browsers will usually always automatically send a new request to that new url x which is line 4.

4👍

Based on user640916’s hint, here’s how I cleaned up the errors.

To urls.py, I added:

url(r'^home$', 'guide.views.home'),

To views.py, I added:

from django.contrib.flatpages.views import flatpage

def home(request):
    return flatpage(request, "/home/")

My server status messages for login now look like:

[17/Aug/2013 09:13:52] "GET / HTTP/1.1" 200 1263
[17/Aug/2013 09:14:00] "POST / HTTP/1.1" 302 0
[17/Aug/2013 09:14:00] "GET /home HTTP/1.1" 200 4529

Not exactly what I was looking for, but it works. I still have the feeling that I’m not doing something right. It appears that django.contrib.auth automatically looks for a home view at the url “/home” without the trailing slash.

3👍

I can’t comment or upvote, but wanted to add for others that beluga.me at https://stackoverflow.com/a/18265990/4651336 was spot on and I was missing a trailing slash after my success_url.

This:

success_url = 'step-two'

changed to:

success_url = 'step-two/'

fixed it.

Leave a comment