1

私は自分のものを繰り返しチェックしましたが、問題を見つけることができません。私のプロジェクトのレイアウトは次のとおりです。

  • 事業
    • すべて
      • 初期化.py
      • admin.py
      • 設定.py
      • models.py
      • ビュー.py
      • tests.py
    • 静的
      • CSS
      • ダヤクス
        • dajaxice.core.js
      • 画像
      • js
    • テンプレート
      • testing.html
    • 事業
      • ajax.py
      • 初期化.py
      • 設定.py
      • urls.py
      • ビュー.py
      • wsgi.py
    • 管理.py

設定.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()

ビュー.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>

アラートを出すボタンを作成するだけです。信じられないほど単純なはずなのに、何も得られません。私は何を間違っていますか?

4

1 に答える 1

1

dajaxice.core.jsは非静的テンプレート ファイルであるためDajaxFinder、それを見つけて一時フォルダーに静的ファイルとして「レンダリング」します。

STATICFILES_DIRSそのため、設定にファイル パスを含めないでください。dajaxice.core.jsそうしないと、ファイルはFileSystemFinderではなくによって検出されますDajaxFinder

findstatic実行して、正しく検出されたかどうかを確認できます。

manage.py findstatic dajaxice\dajaxice.core.js

または多分:

manage.py findstatic dajaxice/dajaxice.core.js

出力結果は一時フォルダー (OS によって異なります) にある必要があり、アプリのどのフォルダーにもあるべきではありません。

于 2013-05-17T01:50:30.243 に答える