Frage

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;
War es hilfreich?

Lösung

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',
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top