Fuscus
Fuscus

Reputation: 11

Dajaxice 0.5.1 - Can't seem to make the tutorial work

I've checked over my stuff repeatedly and I cannot find the issue. Here's the layout of my project:

settings.py

DEBUG = True
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL =/static/

STATICFILES_DIRS = (
    'C:/Python27/djcode/project/static',
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'dajaxice.finders.DajaxiceFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
    'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'project.urls'
WSGI_APPLICATION = 'project.wsgi.application'

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.contrib.auth.context_processors.auth',
    'django.core.context_processors.debug',
    'django.core.context_processors.i18n',
    'django.core.context_processors.media',
    'django.core.context_processors.static',
    'django.core.context_processors.request',
    'django.contrib.messages.context_processors.messages'
)

TEMPLATE_DIRS = (
    "C:/Python27/djcode/project/templates"
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
'allthings',
'dajaxice',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    'django.contrib.admindocs',
)

urls.py

from django.conf.urls import patterns, include, url
from project.views import hello, testing
from dajaxice.core import dajaxice_autodiscover, dajaxice_config
dajaxice_autodiscover()
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    ('^hello/$', hello),
    ('^testing/$', testing),
    url(dajaxice_config.dajaxice_url, include('dajaxice.urls')),

    # Uncomment the admin/doc line below to enable admin documentation:
    url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)


urlpatterns += staticfiles_urlpatterns()

views.py

from django.shortcuts import render_to_response, HttpResponse
from django.template import RequestContext
from dajaxice.core import dajaxice_autodiscover 
dajaxice_autodiscover()

def hello(request):
    return HttpResponse("Hello world!")

def testing(request):
    return render_to_response('testing.html', context_instance = RequestContext(request))

ajax.py

from django.utils import simplejson
from dajaxice.decorators import dajaxice_register

@dajaxice_register
def sayhello(request):
    return simplejson.dumps({'message':'Hello World'})

testing.html

<!DOCTYPE html/>
{% load dajaxice_templatetags %}
<html>
<head><title></title>
{% dajaxice_js_import %}
<script>
function my_callback(data){
    alert(data.message);
}
</script>
</head>
<body>
    This is to test stuff
    <input type="button" onclick="Dajaxice.project.sayhello(my_callback)" value="Get Message from Server"></input>
</body>
</html>

All it does it make a button that puts out an alert. It should be incredibly simple and yet I get nothing. What am I doing wrong?

Upvotes: 1

Views: 872

Answers (1)

jcjason
jcjason

Reputation: 45

Because dajaxice.core.js is a non-static template file, DajaxFinder will find it and 'render' to a temp folder as a static file.

So your STATICFILES_DIRS settings should not contain the file path to dajaxice.core.js otherwise the file will be found by FileSystemFinder rather than DajaxFinder.

You can run findstatic to check it is found correctly or not:

manage.py findstatic dajaxice\dajaxice.core.js

or maybe:

manage.py findstatic dajaxice/dajaxice.core.js

The output result should be in some temp folder (depending on your OS) and should not be in any folder of your app.

Upvotes: 1

Related Questions