Python と django の世界に入ったばかりです。STATIC_URL を使用して URL を設定できません。現在、django 1.4 を使用してローカルで開発しています。django static file docを読んで、必要なものをすべて追加したようですが、それでも 404 エラーが発生します。これに関連する SO に関する他の Q&A を読み、あらゆる種類のことを試しましたが、うまくいきませんでした。
コンソールから取得したエラー
http://localhost:8000/blog/static/js/src/models/myfile.js 404 (NOT FOUND)
他のページが拡張するメイン ページである私の index.html ページには、次のスクリプトがあります。
<script src="{{ STATIC_URL }}/js/src/models/myfile.js"></script>
SOに関する他の質問と回答を調べた後、archive.htmlがデータをレンダリングしているため、追加してビューを編集しようとしました:
from django.template import RequestContext
...
return render_to_response('archive.html', {'categories' : resultSet, 'data': queryData}, context_instance=RequestContext(request))
私のディレクトリ構造 -
mysite
|-- manage.py
|-- mysite
|-- __init__.py
|-- settings.py
|-- urls.py
|-- wsgi.py
|-- blog
|-- __init__.py
|-- models.py
|-- tests.py
|-- views.py
|-- temapltes
|-- archive.html
|-- base.html
|-- static
|-- js
|-- myfile.js
私の設定.py
MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'C:/Python27/Scripts/mysite/blog/static',
# A Bit confused on the path here
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_CONTEXT_PROCESSORS = (
"django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
'django.core.context_processors.static',
)
TEMPLATE_DIRS = ( )
INSTALLED_APPS = (
#..
'django.contrib.staticfiles',
'blog',
)
必要なものはすべて揃っていると思いますが、まだうまくいきません。
どこが間違っているのか、「STATICFILES_DIRS」パスの設定について少し混乱しています。ローカルマシンでこれを機能させるにはどうすればよいですか