django-dajaxice icon indicating copy to clipboard operation
django-dajaxice copied to clipboard

Discovery not filling in required JS module/function handlers

Open scornflake opened this issue 11 years ago • 2 comments

I have been following the setup instructions here: http://django-dajaxice.readthedocs.org/en/latest/installation.html

INSTALLED_APPS and other vars are setup as per doco. A sample view page loads, and contains the JS in the

, but the JS itself looks like this:
var Dajaxice = {








get_cookie: function(name)
{
    var cookieValue = null;
    if (document.cookie && document.cookie != '') {
        var cookies = document.cookie.split(';');
        for (var i = 0; i < cookies.length; i++) {
            var cookie = cookies[i].toString().replace(/^\s+/, "").replace(/\s+$/, "");
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) == (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));

i.e: no module or functions have been generated, thus the JS code doesn't exist to be called, to initiate an AJAX request.

My ajax.py is:

@dajaxice_register(method='GET')
def test_call(request):
    return json.dumps("<b>Foo</b>")

I've inserted logging into my ajax.py, and it's definitely being loaded by auto discovery as part of urls.py.

I have tried to check that dajax is discovering my functions, however (and this may be my limited understanding of python) I cannot iterate the 'modules' properties of dajaxice_functions (it's NoneType) to check that the discovery added something into the dajax state. I get an exception:

for module in dajaxice_functions._modules:
    logger.info("module: {0}".format(module))

TypeError: 'NoneType' object is not iterable

So either my python foo sucks (very possible) or discovery is in fact not registering that function.

I'm at a bit of a loss as to how to proceed. It looks close to working; but the lack of function discovery has me stumped. Any tips / pointers?

scornflake avatar Sep 28 '13 10:09 scornflake

I have a similar problem. My module functions are found in dajaxice.core.js when I run the development server, but when I collect static files they are not in there. I just get what you showed above. Do you also have them when you run dev server?

abakan-zz avatar Oct 16 '13 18:10 abakan-zz

For me the prob was that I didn’t see anywhere at all that I had to collect static, I thought it was dynamic.

Works on both dev+other for me, but then I’m running vagrant + ansible, so dev+prod is the same VM, same codebase...

N

On 17/10/2013, at 7:09 am, Ahmet Bakan [email protected] wrote:

I have a similar problem. My module functions are found in dajaxice.core.js when I run the development server, but when I collect static files they are not in there. I just get what you showed above. Do you also have them when you run dev server?

— Reply to this email directly or view it on GitHub.

scornflake avatar Oct 16 '13 19:10 scornflake