My user registration flow has broken. I have the below code in views.py, but receive a no user.url attribute error (as included beneath the views code). The user’s being created properly and I can navigate to the new user profile page, but the link’s broken. I can’t find info on the default user URL call.
Can you help?
views.py
def register(request):
if request.method == 'POST':
form = UserCreationForm(request.POST)
if form.is_valid():
new_user = form.save()
new_user = authenticate(username = request.POST['username'],
password = request.POST['password1'])
login(request, new_user)
return HttpResponseRedirect(new_user.url)
else:
form = UserCreationForm()
return render_to_response("registration/register.html", {'form': form},
context_instance=RequestContext(request))
Error:
AttributeError at /register/
'User' object has no attribute 'url'
Request Method: POST
Request URL: http://localhost:8000/register/
Django Version: 1.4.1
Exception Type: AttributeError
Exception Value:
'User' object has no attribute 'url'
Exception Location: /home/methuselah/code/django/ssc/dev/ssc/crewcal/views.py in register, line 74
The user object doesn’t have a url. If you want to set a url for every user, you’ll need to create an additional model with a relation to the user model.
I don’t know why you would want to set a unique url for every user though since you can retrieve the user on every request via
request.useronce they’re logged in.So you probably want to just do:
and write another view to handle displaying of the profile. It’s tough to answer without more info about what you’re trying to accomplish.