jrief / django-angular

Let AngularJS play well with Django
http://django-angular.awesto.com/
MIT License
1.23k stars 293 forks source link

Client side error, rmi-function is not a function #332

Closed davidzwa closed 12 months ago

davidzwa commented 6 years ago

Using your examples and trying to tie everything together I am stuck with djangoRMI.process_something is not a function

It seems this is caused by the djng.rmi javascript library. Any idea how to fix this? Maybe provide a FULL example for rmi instead of just snippets?

image

<script type="text/javascript">
    var mainApp = angular.module('btcboardMain', {['djng.rmi']);
    var tags = {% djng_all_rmi %};
    mainApp.config(function (djangoRMIProvider) {
        djangoRMIProvider.configure(tags);
    });

    mainApp.controller("mainCtrl", function ($scope, djangoRMI) {
        $scope.invoke = function () {
            var in_data = {some: 'data'};
            djangoRMI.process_something(in_data)
                .success(function (out_data) {
                    $scope.name = 'Succesful rmi!';
                });
        };
        $scope.name = 'Didnt do anything!';
    });
</script>

Django viewsRMI.py

def index(request):
    context = {}
    return render(request, 'home.html', context)

class MyJSONView(JSONResponseMixin, ContextMixin, View):

    @allow_remote_invocation
    def process_something(self, in_data):
        # process in_data
        print("asd")
        out_data = {
            'foo': 'bar',
            'success': True,
        }
        return out_data

Django urls

from django.urls import *

from main import views, viewsRMI

urlpatterns = [
    path('', views.index, name='main'),
    path('re', viewsRMI.MyJSONView.as_view(), name='remote'),
]
davidzwa commented 6 years ago

So far I reverted to DRF and completely stepped of django-angular, since the RMI implementation is not very angular-friendly anyway. In any case I would still like to have a solution to the problem above, since I am planning to make a back-end management system through Jinja2+AngularJS without Node.