def post(self,request): serialized = UserSerializer(data=request.DATA) if request.DATA.get('password') != request.DATA.get('confirm_password'): if request.DATA.get("admin_panel"): return util.return_html("user_register.html",{'confirm_password_error':'Passwords do not match'}) else: return Response(serialized.errors, status=status.HTTP_400_BAD_REQUEST) else: if serialized.is_valid(): user = User.objects.create_user( serialized.init_data['username'], serialized.init_data['email'], serialized.init_data['password'] ) profile = Profile(user=user,email=user.email,username=user.username) profile.check_save() if request.DATA.get('admin_panel'): return redirect('/admin_panel/'); else: return Response(status=status.HTTP_201_CREATED) else: if request.DATA.get("admin_panel"): return util.return_html("user_register.html",serialized.errors) else: return Response(serialized.errors, status=status.HTTP_400_BAD_REQUEST)
def get(self,request): # Load the template myblog/templates/index.html template = loader.get_template('user_register.html') # Context is a normal Python dictionary whose keys can be accessed in the template index.html return util.return_html('user_register.html', {})