Saad Abdullah
Saad Abdullah

Reputation: 2432

No handler could be found for logger "dajaxice"

AoA, I am trying to make ajax call, when i use function args_example, it posts successfully and I get the response "Message is "... but If I call the function change(same as args_example) I get an error in console(No handler could be found for logger dajaxice)

//ajax.py

 from django.utils import simplejson
    from contacts.models import Notifications
    from dajaxice.decorators import dajaxice_register

@dajaxice_register

def args_example(request):
    return simplejson.dumps({'message':'Message is '})

def change(request):
    return simplejson.dumps({'message':'Message is '})

//Javascript

function in template
 setInterval(function(){

      Dajaxice.contacts.change(callback);

  },2000);

Upvotes: 0

Views: 589

Answers (1)

frixx
frixx

Reputation: 143

My guess is that this is a django error which is passed via ajax to the browser console. Have a look at django-dajaxice/dajaxice/core/Dajaxice.py where Dajaxice defines its own error logger log = logging.getLogger('dajaxice') at the top. So what you need to do is to adapt your projects settings.py and define this logger with an existing handler e.g.:

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
    'require_debug_false': {
        '()': 'django.utils.log.RequireDebugFalse'
    },
    'require_debug_true': {
        '()': 'django.utils.log.RequireDebugTrue'
    },
},
'handlers': {
    'mail_admins': {
        'level': 'ERROR',
        'filters': ['require_debug_false'],
        'class': 'django.utils.log.AdminEmailHandler'
    },
    'debug_console': {
        'level': 'DEBUG',
        'filters': ['require_debug_true'],
        'class': 'logging.StreamHandler'
    },
},
'loggers': {
    'django.request': {
        'handlers': ['mail_admins'],
        'level': 'ERROR',
        'propagate': True,
    },
    'dajaxice': {
    'handlers': ['debug_console'],
    'level': 'WARNING',
    'propagate': False,
    },
}
}

Note that this example needs Django >=1.5 because of the django.utils.log.RequireDebugTrue.

This will of course not solve your porblem but at least you get to the real error message. For detailed informatin about Django logging please read the official docs.

The real django error comes from the fact that @dajaxice_register is a method decorator that has to be put in front of every method you want to use in dajax. Change your ajax.py to:

from django.utils import simplejson
from contacts.models import Notifications
from dajaxice.decorators import dajaxice_register

@dajaxice_register 
def args_example(request):
    return simplejson.dumps({'message':'Message is '})

@dajaxice_register 
def change(request):
    return simplejson.dumps({'message':'Message is '})

Upvotes: 1

Related Questions