Reputation: 943
I am getting this error:
Internal Server Error: /signup/
Traceback (most recent call last):
File "C:\python\lib\site-packages\django\core\handlers\exception.py", line 41, in inner
response = get_response(request)
File "C:\python\lib\site-packages\django\utils\deprecation.py", line 142, in __call__
response = self.process_response(request, response)
File "C:\python\lib\site-packages\django\middleware\clickjacking.py", line 32, in process_response
if response.get('X-Frame-Options') is not None:
AttributeError: 'str' object has no attribute 'get'
When trying to render this view:
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
new_user = form.save(commit=False)
new_user.is_active = False
new_user.save()
current_site = get_current_site(request)
subject = "Activate your DC-Elects account"
message = render_to_string('registration/account_activation_email.html', {
'user': new_user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(new_user.id)),
'token': account_activation_token.make_token(new_user),
})
new_user.email_user(subject, message)
return reverse('elections:account_activation_sent')
else:
form = SignUpForm()
return render(request, 'registration/signup.html',{
'form': form,
})
The error message is not very descriptive, but the email is sending with the link correctly, so I'm very confused as to why there is an error. How do I prevent this error and render the next view correctly?
Upvotes: 2
Views: 45
Reputation: 47374
Django's view function should return HttpResponse
object. reverse
is just a method which generate url string, not response object, so this line:
return reverse('elections:account_activation_sent')
raise the error.
If you need redirect use redirect
shortcut:
return redirect('elections:account_activation_sent')
Upvotes: 4