In a Django 1.8 app I have a form that is posting using Angular.js. After the form has been submitted by Angular to Django Rest Framework I would like to move to another Django view. My question is how to move to another Django view apart from using $windows.location.href?
At the moment I'm using $windows.location.href but I would like Django(meaning not Javascript/Angular) to move to another page. Here's how I do it now - for brevity here's a small part of this form in my template:
<div ng-app="pacjent">
(...)
<div ng-controller="NewPatientCtrl">
(...)
<form name="newPatientForm" ng-submit="newPatientForm.$valid && submitNewPatientForm()" ng-init="initialize('{{user.id}}')" novalidate>
{% csrf_token %}
(...)
</form>
This form is posting all data to Django Rest Framework like this:
function submitNewPatientForm(){
/* it's prime goal is to submit name,surname, age & phone to createNewPatient API */
$scope.setBusy = true;
savePatient = $http({
method: 'POST',
url: 'http://localhost:8000/pacjent/api/createNewPatient/',
data: $scope.newPatient,
})
.then(function successCallback(response){
newPatient = response.data['id'];
createNewTherapyGroup();
url = patientDetailView + response.data.id + '/';
$window.location.href=url; # I DON"T WANT TO USE THIS, but I don't know how!
}, function errorCallback(response){
if (response['data']['name'] && response['data']['surname']) {
$scope.newPatientForm.newPatientName.$setValidity("patientExists", false);
$scope.errors.newPatientName =response.data['name'][0];
}
(...)
Is there a way to do it differently?