1

I'm trying to create a basic submit form (like the dajaxice's example) but i keep receiving a 404 error from firebug console:

404 NOT FOUND 386ms 
"NetworkError: 404 NOT FOUND - http://<my_website>/dajaxice/maynard.maynard_core.subscribe/"

My project folder structure is

/maynard/maynard_core/

This folder contains the main files of the project (views.py, ajax.py etc etc... main django project folder) Inside the ajax.py file, there's the subscribe method:

from dajax.core import Dajax
from dajaxice.core import dajaxice_functions
from dajaxice.decorators import dajaxice_register
from views import subscribe_search
from forms import SubscriptionForm, SendMailForm
from django.core.mail import send_mail


def subscribe(request, form):

     if request.POST:
        dajax = Dajax()

        form = SubscriptionForm(form)

        try:
             if form.is_valid():
                url = form.cleaned_data['url_sub']
                what = form.cleaned_data['what_sub']
                where = form.cleaned_data['where_sub']
                mail = form.cleaned_data['email']

                subscribe_search(url,what,where,mail)
                dajax.assign('#sub_mess_top','innerHTML','Thank you for subscribing to the search')

             else:
                dajax.add_css_class('#sub_mess_top','text error-message')
                dajax.assign('#sub_mess_top','innerHTML','Couldn\'t complete the request, try again!')

             return dajax.json()

        except:
            dajax.add_css_class('#sub_mess_top','text warning-message')
            dajax.assign('#sub_mess_top','innerHTML','You already saved this search')
            return dajax.json()
dajaxice_functions.register(subscribe)

Which is then called via this js method

function send_form_top(){
    data = $('#subscribe').serializeObject(true);
    Dajaxice.maynard.maynard_core.subscribe(Dajax.process,{'form':data});
}

The form is a basic form with action "#" and onclick="send_form_top();"

I followed the installation and configuration guide (settings configured, urls configured etc etc etc), and it's a very 101 implementation.

in urls.py

from dajaxice.core import dajaxice_autodiscover
dajaxice_autodiscover()
...
django.conf.urls.defaults.url(r'^%s/' % settings.DAJAXICE_MEDIA_PREFIX, django.conf.urls.defaults.include('dajaxice.urls')),

I added 'dajaxice' to my installed apps in settings.py, and DAJAXICE_MEDIA_PREFIX is 'dajaxice' (as in the docs). Templates are fine too (since i have the dajaxice dynamically compiled js included)

But still i can't seem to be able to make it work. I checked throu the response headers, and this is what i get for the dajax.js file:

maynard_core: {


   subscribe: function(callback_function, argv, custom_settings){
        Dajaxice.call('maynard.maynard_core.subscribe', callback_function, argv, custom_settings);
    },
...

This tells me that the submit method, which is in the ajax.py file inside maynard/maynard_core/ is actually included and the callback is correct too. I really don't know how to debug this any more, django logs shows nothing about it. Thanks all in advance, i'm really loosing my hair on this.

Samuele Mattiuzzo
  • 10,760
  • 5
  • 39
  • 63
  • 1
    little comment: in the subscribe method there's both dajaxice decorators and function_register. that's just because i tried them both and there's no difference using @dajaxice_register or dajaxice_functions.register(subscribe). code is not messy :) – Samuele Mattiuzzo Jan 02 '12 at 10:30

1 Answers1

0

If you got a 404 error, definitely the problem is in your urls.py configuration. There is any wildcard url above the dajaxice one? Try to put the dajaxice url conf on the beginning and see what happens.

Anyway... are your views.py, ajax.py, etc... inside any app? or all of them are in the root project folder. That could be the problem too.

Jorge Bastida
  • 535
  • 5
  • 10
  • views.py and ajax.py are inside the maynard_core app, urls.py is into the root folder. tomorrow i'll try to put the dajaxice url conf at the beginning. we have an nginx serving statics, can that be the problem? do i have to tell nginx that /dajaxice/ is a valid url? or what? thanks – Samuele Mattiuzzo Jan 03 '12 at 00:12
  • i did as you told me (http://pastie.org/3117670 and meanwhile the project changed name too) and nothing changes. also, i have a new strange behaviour: i changed the subscribe function name into "subscribe_test" (i tought about name clashes or similar, since "subscribe" is a common name) and apparently the method doesn't get registered... i'm really confused now – Samuele Mattiuzzo Jan 03 '12 at 10:59
  • i had to drop dajaxice because of our nginx proxypass configuration and it's a real shame because i liked it in the previous project. thanks anyway jorge – Samuele Mattiuzzo Jan 04 '12 at 12:38