I'm trying to do a GET request from angular passing through a parameter to django's view.py.
The url that I'm getting back is /contact/api/getName?name=John
and neither of them is hitting api_get_client_info in views.py because the string and values inside api_get_client_info are being printed. But I am getting a "success" message after the request.
HTML:
<select ng-change="selectName(name)" ng-model="name">
<option value="" disabled>Select from List</option>
<option ng-repeat="name in nameList" value="{{name.Name}}"> {{name.Name}} </option>
</select>
$http.get request in angular controller:
$scope.selectName= function(name){
Method 1:
$http.get("/contact/api/getName", {params: {"personName": name}})
.success(function(response) {
console.log("success");
})
.error(function(response){
console.log("failed");
})
Method 2:
$http({
method:'GET',
url: '/contact/api/getName?=' + name
})
.success(function(data) {
console.log("success");
})
.error(function(data){
console.log("failed");
})
}
Django url.py
urlpattern = [
url(r'^api/getName(?P<personName>[a-zA-Z0-9_]+)/$', views.api_get_person_info),
url(r'', views.main, name='contact',
]
Django views.py
def api_get_person_info(request):
print("here")
person = request.GET.get("personName")
print(person)