def post(self, request): form = SignupForm(request.POST) if form.is_valid(): #Guardar el usuario nuevo new_user = form.save() blog = Blog() blog.name = "Blog de {}".format(new_user.username) blog.owner = new_user blog.save() #Poner los campos en blanco form = SignupForm() return redirect('posts_home') else: #Pregunta. En el html pq no me pinta los campos de nuevo form = SignupForm() context = { 'signup_form': form, 'message': 'Hay errores en el formulario. Intenta de nuevo.' } return render(request, 'users/signup.html', context)
def perform_create(self, serializer): user = serializer.save() blog = Blog() blog.name = "Blog de {}".format(user.username) blog.owner = user blog.save()