-1
I may misunderstand your intension.
But I think when the form is valid you should do something like:
if form.is_valid():
actkey = request.POST['actkey']
activate( '', actkey )
return render_to_response( 'profile/register.html', { 'message' : message } )
ie. omit the form object after you activate the user.
5
You should redirect after a successful form submission
if request.method == 'POST':
form = ActivateForm( request.POST )
if form.is_valid():
actkey = form.cleaned_data['actkey']#access cleaned_data instead of raw post
activate( '', actkey )
return HttpResponseRedirect('/')
3
The best way to solve this problem is using a redirect to the previous page:
return redirect(request.META['HTTP_REFERER'])
- [Django]-Passing Editable Fields as validated_data method of Django-Rest-Framework Serializer
- [Django]-Django โ 403 Forbidden. CSRF token missing or incorrect
- [Django]-Django: How to remove bullet point when printing form errors
0
Itโs both not quite what i was looking for, but i fixed it this way:
def activate( request = '', actkey = "" ):
message = ""
if len( actkey ) != 40:
if request.method == 'POST':
form = ActivateForm( request.POST )
if form.is_valid():
actkey = request.POST['actkey']
profile = userprofile.objects.get( actkey = actkey )
user = User.objects.get( id = profile.user_id )
user.is_active = True
user.save()
profile.actkey = ""
profile.save()
message += "Uw account is succesvol geactiveerd."
return render_to_response( 'profile/register.html', { 'message' : message } )
else:
form = ActivateForm()
else:
profile = userprofile.objects.get( actkey = actkey )
user = User.objects.get( id = profile.user_id )
user.is_active = True
user.save()
profile.actkey = ""
profile.save()
message += "Uw account is succesvol geactiveerd."
return render_to_response( 'profile/register.html', { 'message' : message } )
return render_to_response( 'profile/register.html', { 'message' : message, 'form' : form } )
Thanks for the replies
- [Django]-Django query โ Is it possible to group elements by common field at database level?
- [Django]-How to import data from scanned text into Django models
- [Django]-Allowing basic html markup in django
- [Django]-Django project /admin Site matching query does not exist
Source:stackexchange.com