0

Django 1.3 に関する 10 億番目の静的ファイルの質問のように。私は非常に多くのことを検索して試してきましたが、何もうまくいかないようです。どんな助けでも大歓迎です。できるだけ多くの情報を提供しようとします。

URLファイル

urlpatterns = patterns('',
url(r'^projectm/statictest/$','project_management.views.statictest'),)

見る

def statictest(request):
return render_to_response('statictest.html',locals())

テンプレート

<html><head><title>Static Load Test Page</title></head>
<body>
{% load static %}
<img src="{{ STATIC_URL }}testimage.jpg" />
</body></html>

設定

STATIC_ROOT = '/home/baz/framework/mysite/static/'
STATIC_URL = '/static/'
STATICFILES_DIRS = ('',)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
TEMPLATE_DIRS = (
"/home/baz/framework/mysite/templates"

ファイル

-bash-3.2$ pwd
/home/baz/framework/mysite/templates
statictest.html

-bash-3.2$ pwd
/home/baz/framework/mysite/project_management/static
-bash-3.2$ ls
testimage.jpg

他に役立つ情報があるかどうかはわかりません。しかし、基本的にこのテストページにアクセスしてページソースを確認すると、URLは

<img src="/static/testimage.jpg" />

ただし、画像は読み込まれません。私も複数のブラウザでこれを試しました。どこかで imort ステートメントが欠落している可能性がありますか?

助けに乾杯

4

2 に答える 2

0

また、「STATIC_ROOT」を設定したら、必ず「collectstatic」管理コマンドを実行してください。

https://docs.djangoproject.com/en/1.4/howto/static-files/#deploying-static-files-in-a-nutshell

于 2013-02-18T02:05:04.987 に答える
0

Are you using the built in runserver command or do you serve the Django app some other way?

If you use runserver then your problem is that you don't tell Django where to find your static assets in the filesystem. You need to set STATIC_ROOT to a filesystem path where your static assets can be found. Try setting it to: /home/baz/framework/mysite/project_management/static/

If you are using a different server (like gunicorn behind Nginx for example) then it is the responsibility of the front-end server to intercept requests for /static/ and serve them for you.

于 2013-02-18T01:59:29.523 に答える