JavaScript Simple Django-swampdragon + AngularJS real-time app

I use django-swampdragon + angularjs to create simple django app which shows website requests in real-time.

All of the Django logic is okay, but when I try make it respond in real-time the system kind of fails. I think the problem is in Angular, since I haven't used it before.

So, the django-swampdragon part of code:

# routers.py 
from swampdragon import route_handler
from swampdragon.route_handler import ModelRouter

from .serializers import HttpRequestSerializer
from .models import HttpRequest


class HttpRequestRouter(ModelRouter):
    serializer_class = HttpRequestSerializer
    model = HttpRequest
    route_name = 'activity-route'

    def get_object(self, **kwargs):
        return self.model.objects.get(pk=kwargs['pk'])

    def get_query_set(self, **kwargs):
        return self.model.all()


route_handler.register(HttpRequestRouter)

The Angular.js part of code

// controllers.js
var ActivityControllers = angular.module('ActivityControllers', []);

ActivityControllers.controller('ActivityCtrl', ['$scope', '$dragon', function ($scope, $dragon) {
    $scope.channel = 'httprequests';
    $scope.datasource = [];

    // Subscribe to the activity router
    $dragon.onReady(function() {
        $dragon.subscribe('activity-route', $scope.channel, {}).then(function(response) {
            this.dataMapper = new DataMapper(response.data);
        });
        $dragon.getList('activity-route', {}).then(function(response) {
            $scope.datasource = response.data
        });
    });

    $dragon.onChannelMessage(function(channels, new_request) {
        if (indexOf.call(channels, $scope.channel) > -1) {
            $scope.$apply(function() {
                $scope.datasource.unshift(new_request);
            });
        }
    });

}]);

And, finally, my template part:

<div ng-controller="ActivityCtrl">
    <ul ng-repeat="req in datasource">
        <li>
            <span class="request_date">{$ req.date $} ...</span>
        </li>
    </ul>
</div>

When I run server.py and open browser on that url/port (http://localhost:9999/) i have this error (in browser):

Traceback (most recent call last):
  File "...lib/python3.4/site-packages/tornado/web.py", line 1323, in _execute
    result = self.prepare()
  File "...lib/python3.4/site-packages/tornado/web.py", line 2014, in prepare
    raise HTTPError(self._status_code)
tornado.web.HTTPError: HTTP 404: Not Found

And also this error on the console:

-------- SwampDragon ------
Running SwampDragon on 127.0.0.1:9999
DRAGON_URL: http://localhost:9999/
Version 0.4.2
Debug: True
Quit the server with ctrl+c
---------------------------
WARNING:tornado.access:404 GET / (127.0.0.1) 206.58ms

And, of course, my page with request don't work either.

PLease help me find the error!

Answer:1

I am trying to read the ID3 tags of an music file. Currently i have a Dataview object with the last 128 bits of an audio file in it (because the ID3 tags are at the last 128 bits in a audio file). So ...

I am trying to read the ID3 tags of an music file. Currently i have a Dataview object with the last 128 bits of an audio file in it (because the ID3 tags are at the last 128 bits in a audio file). So ...

  1. javascript dataview read string

I am using javascript to create html page , but not able to call some function on button click . var alernative = "plot1"; var buttonvalue= "mybutton"; function callme() {alert("hello");} $('#'...

I am using javascript to create html page , but not able to call some function on button click . var alernative = "plot1"; var buttonvalue= "mybutton"; function callme() {alert("hello");} $('#'...

  1. calling function from another file python
  2. calling function from another script unity
  3. calling function from another file matlab
  4. calling function from another function in python
  5. calling function from another class c++
  6. calling function from header file c++
  7. calling function from class c++
  8. calling function from another file javascript
  9. calling function from class python
  10. calling function from dictionary python
  11. calling function from another class
  12. calling function from another file in c
  13. calling function from another class java
  14. calling function from another class python
  15. calling function from another file php
  16. calling function from html angular
  17. calling function from external js file
  18. calling function from main java
  19. calling function from html
  20. calling function from another component react

simple javascript but can't seem to get it to work. var number = 5; var netiteration = "net"+number; // makes netiteration now equal net5 var formvalue = document.forms.myformname.netiteration....

simple javascript but can't seem to get it to work. var number = 5; var netiteration = "net"+number; // makes netiteration now equal net5 var formvalue = document.forms.myformname.netiteration....

  1. javascript form value by name
  2. javascript form value set
  3. javascript form value get
  4. javascript form value
  5. javascript form value change
  6. javascript form value length
  7. javascript form value array
  8. javascript form value check
  9. javascript form value by id
  10. javascript form value clear
  11. javascript form value select
  12. javascript form value empty
  13. javascript form value validation
  14. javascript form value to variable
  15. javascript form value checkbox
  16. javascript form value update
  17. javascript value form dropdown
  18. javascript form input value
  19. javascript change form value before submit
  20. javascript form field value

I've tried to make the Material Design Slide Indicator (watch image) with javascript. I use Ionic to control the slides (to "swipe", to set slide or to obtain the current slide) but the prolem doesn'...

I've tried to make the Material Design Slide Indicator (watch image) with javascript. I use Ionic to control the slides (to "swipe", to set slide or to obtain the current slide) but the prolem doesn'...