Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

441
Vistas
How to connect a Django view with angular js Front end?

I'm fairly new to Django rest and angularjs. I'm trying to create a Django view which will have a function and this function has to be called via a button in angular js. Can anyone please help me out? Thanks

about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

This might help: Django - Angular Tutorial

General answer would be: 1) Using for example Django REST expose your method (endpoint) 2) From Angular application send request to the previously exposed endpoint.

about 4 years ago · Santiago Trujillo Denunciar

0

say this is your Django/python api end point (assume controller file to be random.py)

def getRandomInfo(request):
try:
    result = database.getRandomInfo()
    return JsonResponse(result, content_type="application/json", safe=False)
except Exception as e:
    import traceback
    traceback.print_exc(e)
    return JsonResponse({error:'sorry'}, content_type="application/json", safe=False)

Via angular, provided you have resolved all the dependencies and have a functioning angular app and/or controller set up in your html/js

you can call the api using below code

app.controller("appControllerName", function ($scope, $http) {
    $http.get("{% url 'getRandomInfo' %}")
            .success(function (response, status) {
                response_data = response
                $scope.data = response_data;
            }).error(function (response, status) {
        $scope.status = status;
    });
  }

if you notice the {% url 'getRandomInfo' %} , this is defined in your urls.py , u'll have to add a line like this over there where getRandomInfo will have to be the 'name' of the url

url(r'^random/getRandomInfo/$',random.getRandomInfo, name='getRandomInfo'),

Over here you controller name is random and a function within that controller is def getRandomInfo, so django allows two ways to access this endpoint, either via the url r'^random/getRandomInfo/$ (yes regex is allowed here) or via the name as stated in the example here.

Best of Luck :)

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda