2

I'm a nooby to django and I tried many hours to get a simple example of dajaxice running, but I don't seem to find the right way to look for the files.

I did and redid installation and tried to find answers in the numerous similar questions on stackoverflow like this one and this one.

I put {% dajaxice_js_import %} in the header of myapp_index.html which prints out as:

<script src="/static/dajaxice/dajaxice.core.js"
    type="text/javascript" charset="utf-8"></script>

but it cannot find this file:

ImproperlyConfigured: The storage backend of the staticfiles finder doesn't have a valid location.

And the get fails:

GET /static/dajaxice/dajaxice.core.js HTTP/1.1" 500 59

Strangely enough dajax loads:

<script type="text/javascript" 
    src="{% static  /static/dajax/jquery.dajax.core.js" %}"></script>

Here's my folder structure:

myproject  
----manage.py  
----myproject  
--------settings.py  
--------urls.py  
----myapp  
--------ajax.py  
--------urls.py  
--------templates  
------------myapp_index.html  

I also haven't really understood why we need two urls.py files, but somehow it seems to access myapp_index.html if I put

from django.views.generic.simple import direct_to_template

and then

url(r'^$', direct_to_template, {'template': 'myapp_index.html'}),

in myapp's url patterns.

I also tried uncountable filenames in

python manage.py findstatic dajaxice.core.js

but somehow it doesn't find dajaxice, even though dajaxice is installed and accepted in the settings.py file among the INSTALLED_APPS.

Also python manage.py collectstatic fails for the same reason, but if I understood correctly, I don't event have to make it run as long as I'm on a development server.

I guess I have some basic misunderstanding of the underlying structure. :(

I'm using the prepacked latest ubuntu packages:

django: 1.4.5, 
dajaxice: 0.5.5

Thanks in advance for any hint!

here is the template file:

{% load static %}
{% load dajaxice_templatetags %}

<html>
  <head>
    <title>My base template</title>
    {% dajaxice_js_import %}
    <script type="text/javascript" src="{% static "/static/dajax/jquery.dajax.core.js" %}"></script>

<script type="text/javascript">
function my_js_callback(data){
alert(data.message);
}
Dajax;
Dajaxice;
  </script>
 </head>
...
 <button      onclick="Dajaxice.myproject.myapp.sayhello(my_js_callback);">Click here!</button>

I get no Django error, the page shows, but I get this in Firebug:

"NetworkError: 500 Internal Server Error -  http://localhost:8000/static/dajaxice/dajaxice.core.js"

and this:

ReferenceError: Dajaxice is not defined
Dajaxice;
Community
  • 1
  • 1
kmgrds
  • 131
  • 2
  • 13
  • Please paste the output of `./manage.py collectstatic --noinput`. – Ivan Kharlamov May 04 '13 at 21:00
  • Also, check that you have `DEBUG=True` in `settings.py`, launch [firebug](https://addons.mozilla.org/en-US/firefox/addon/firebug/), open `Console` tab and reload your page. You should see something like Django error page with detailed information about the error in Firebug console log. – Ivan Kharlamov May 04 '13 at 21:11
  • I edited my original question to include what you asked for. – kmgrds May 04 '13 at 21:21

1 Answers1

2

It seems that you've messed up your urls.conf. It should contain something like:

url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),

Does it?

Also, the STATICFILES_FINDERS section of your settings.py file should include:

 'dajaxice.finders.DajaxiceFinder',
Ivan Kharlamov
  • 1,889
  • 2
  • 24
  • 33
  • Thanks for the quick answer! My STATICFILES_FINDERS had the third line (DefaultStorageFinder) uncommented, but I tried both and it doesn't make a difference, I tried commented and uncommented. Any other idea what I could check? – kmgrds May 04 '13 at 21:03
  • Hi! @kmgrds, please paste the output of `./manage.py collectstatic --noinput`. – Ivan Kharlamov May 04 '13 at 21:03
  • Too long for the comment: hope this tail is enough: return self.nodelist.render(context) File "/usr/lib/python2.7/dist-packages/django/template/base.py", line 823, in render bit = self.render_node(node, context) File "/usr/lib/python2.7/dist-packages/django/template/debug.py", line 74, in render_node return node.render(context) File "/usr/lib/python2.7/dist-packages/django/template/defaulttags.py", line 424, in render raise e django.core.urlresolvers.NoReverseMatch: Reverse for 'dajaxice-endpoint' with arguments '()' and keyword arguments '{}' not found. – kmgrds May 04 '13 at 21:09
  • 1
    Oh, it seems that you've messed up your `urls.conf`. It should contain something like `url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),`. Does it? – Ivan Kharlamov May 04 '13 at 21:13
  • 2
    Thanks so much! That was it! Actually, I had the line in my urls.py file in my app, but I didn't have it in my urls.py file of the project. I still haven't quite grasped this distinction. Thanks again for this quick help! – kmgrds May 04 '13 at 21:27
  • @Kmgrds, you're welcome! Have a nice day! And I'm going to bed now. :)) – Ivan Kharlamov May 04 '13 at 21:35