申し訳ありませんが、同様の質問が何度も寄せられていることは承知しています...もう一度質問するのは本当に申し訳ありませんが、これには非常に問題があります(私は何時間もかけてすべてを試しましたが、何の進歩も感じられない)、具体的な助けを求めようと思った.
Dreamhost で Django アプリをセットアップしようとしています。私は正常に動作しているvirtualenvを介してDjango 1.5を使用しています。ただし、Django は私の静的ファイルを見つけることができないようです。私のセットアップは次のとおりです。
私のサイト ディレクトリ:
~/distracti.co.uk $ tree
.
├── distracti
│ ├── distracti
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── manage.py
│ └── polls
│ ├── __init__.py
│ ├── admin.py
│ ├── models.py
│ ├── static
│ │ ├── images
│ │ │ └── test.png
│ │ └── style.css
│ ├── templates
│ │ └── polls
│ │ ├── index.html
│ │ └── style.css
│ ├── tests.py
│ ├── urls.py
│ └── views.py
├── django-setup.py
├── passenger_wsgi.py
├── public
│ ├── favicon.gif
│ ├── favicon.ico
│ └── quickstart.html
├── static
└── tmp
├── default_passenger_wsgi.py
├── old_passenger_wsgi.py
├── passenger_wsgi.py
└── restart.txt
10 directories, 24 files
~/distracti.co.uk/distracti/distracti/settings.py の重要な部分 (と思います):
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = '/home/<myusername>/distracti.co.uk/static/'
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
# Additional locations of static files
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.
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
#... other context processors
)
...
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'polls',
)
その後、実行できます
python manage.py collectstatic
アプリ固有の静的ファイル (多くの Django 管理用静的ファイルと共に) は、STATIC_ROOT フォルダーに収集されます。
73 static files copied.
~/distracti.co.uk $ ls static/ static/images
static/:
admin images style.css
static/images:
test.png
ブラウザに提供される index.html ファイルの先頭は次のとおりです。
{% load staticfiles %}
<head>
<link rel="stylesheet" type="text/css" href="{% static 'style.css' %}" />
</head>
<img src="{% static 'images/test.png' %}">
リンクがブラウザに次のように表示されるため、少なくともこの部分は機能していると言えます。
<link rel="stylesheet" type="text/css" href="/static/style.css">
これが機能すると私が考えた方法は、Django が STATIC_URL ('/static/') を href 文字列から削除し、残りの文字列を相対的な場所として使用して STATIC_ROOT ディレクトリ内のファイルを探すことです。残りが「style.css」であることを考えると、Django は私の STATIC_ROOT ディレクトリで style.css ファイルを見つけることができると考えていたでしょう。
[recall STATIC_ROOT = '/home/<myusername>/distracti.co.uk/static/']
~/distracti.co.uk $ ls static/
static/:
admin images style.css
したがって、ファイルは私の STATIC_ROOT ディレクトリでブラウザに送信されるのを待っています!!
ただし、できる限り試してみてください。これは機能しません... :(私のcssおよびpngファイルは、ブラウザで404エラーに遭遇します:
GET http://www.distracti.co.uk/static/style.css 404 (NOT FOUND)
GET http://www.distracti.co.uk/static/images/test.png 404 (NOT FOUND)
どんな助けでも大歓迎です。こんなに簡単なことがこんなに難しいとは思っていなかったので、アドバイスをいただければ幸いです。Django がこれらのファイルを見つけるプロセスを理解していないのはとてもイライラします。
ありがとう
ガレス