3

静的ファイルが配信されないのはなぜですか? または私が言うことができないそれらのいくつかだけ。私はほぼすべてを試しました。どこに問題があるのか​​ わかりません。開発中および生産中に静的ファイルを機能させるためのサポートが必要です。しかし、最初に開発を手伝ってください

静的ファイルを機能させようとしていますが、このエラーが発生します

Django version 1.4.3, using settings 'menu.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[10/Mar/2013 15:12:37] "GET / HTTP/1.1" 200 1868
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/handlers.py", line 68, in __call__
    start_response)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/handlers.py", line 57, in get_response
    return self.serve(request)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/handlers.py", line 50, in serve
    return serve(request, self.file_path(request.path), insecure=True)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/views.py", line 36, in serve
    absolute_path = finders.find(normalized_path)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/finders.py", line 238, in find
    for finder in get_finders():
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/finders.py", line 256, in get_finders
    yield get_finder(finder_path)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/utils/functional.py", line 27, in wrapper
    result = func(*args)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/finders.py", line 277, in _get_finder
    (Finder, BaseFinder))
ImproperlyConfigured: Finder "<class 'django.contrib.staticfiles.finders.FileSystemFinder'>" is not a subclass of "<class 'staticfiles.finders.BaseFinder'>"
[10/Mar/2013 15:12:37] "GET /static/css/screen.css HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/handlers.py", line 68, in __call__
    start_response)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/handlers.py", line 57, in get_response
    return self.serve(request)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/handlers.py", line 50, in serve
    return serve(request, self.file_path(request.path), insecure=True)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/views.py", line 36, in serve
    absolute_path = finders.find(normalized_path)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/finders.py", line 238, in find
    for finder in get_finders():
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/finders.py", line 256, in get_finders
    yield get_finder(finder_path)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/Django-1.4.3-py2.7.egg/django/utils/functional.py", line 27, in wrapper
    result = func(*args)
  File "/home/talisman/virt_env/menu/local/lib/python2.7/site-packages/staticfiles/finders.py", line 277, in _get_finder
    (Finder, BaseFinder))
ImproperlyConfigured: Finder "<class 'django.contrib.staticfiles.finders.FileSystemFinder'>" is not a subclass of "<class 'staticfiles.finders.BaseFinder'>"
[10/Mar/2013 15:12:37] "GET /static/css/print.css HTTP/1.1" 500 59

これは私のsettings.pyです

if socket.gethostname() == 'Pangolin': #Brian's Development Laptop
    DEBUG = TEMPLATE_DEBUG = True
    TEMPLATE_DIRS = ('/home/talisman/projects/menu/templates',)
    SQL_LITE_NAME = '/home/talisman/projects/menu/db4.db'
    STATIC_ROOT = '/home/talisman/projects/menu/static/'
    STATICFILES_DIRS = (
        # Put strings here, like "/home/html/static" or "C:/www/django/static".
        # Always use forward slashes, even on Windows.
        # Don't forget to use absolute paths, not relative paths.
        '/home/talisman/projects/menu/staticfiles/',
        )
4

1 に答える 1

3

設定で静的ファイルを誤って構成した可能性がありますか?

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)

コンテキストプロセッサがあることを確認してください。

TEMPLATE_CONTEXT_PROCESSORS = [
    ...
    'django.core.context_processors.static',
    ...
]

また、絶対パスを提供するために使用されるそのようなパスを使用しないでください...

from os.path import join, dirname, normpath

LOCAL_PATH = normpath(join(dirname(__file__), '..'))

その後、あなたはすることができます...

# Additional locations of static files
STATICFILES_DIRS = (
    LOCAL_PATH + '/public/common/',
)

=========

これが私のセットアップ方法の例です

MEDIA_ROOT = ''
MEDIA_URL = ''

STATIC_ROOT = '/uploaded/'
STATIC_URL = '/static/'

# Additional locations of static files
STATICFILES_DIRS = (
    LOCAL_PATH + '/public/common/',
)

    # List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

インストールしたアプリで、

'django.contrib.staticfiles',
于 2013-03-10T20:29:54.397 に答える