WindowsXPでdjango1.3、python2.7を実行しています
djangoアプリの静的フォルダーにcssをセットアップしようとしています。
テンプレートは次のようになります。
<html>
<head>
<title>css demo</title>
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/my.css" />
</head>
<body>
生成されたHTMLは次のようになります。
<html>
<head>
<title>css demo</title>
<link rel="stylesheet" type="text/css" href="http://localhost/static/css/my.css" />
</head>
...
したがって、静的ファイルがテンプレートのどこにあるか、次に生成されたhtmlのどこにあるかを指定するために、すべてを設定したようです。
ただし、「 http://localhost/static/css/my.css 」に注意があります。どうすればそこに着くことができますか?
私は次のようにcollectstaticを実行しました:
C:\root\workspace\mywebapp\src\mywebapp>c:\Python27\python.exe manage.py collectstatic
You have requested to collect static files at the destination location as specified in your settings file.
This will overwrite existing files.
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Copying 'c:\root\workspace\mywebapp\src\mywebapp\css_demo\static\css\my.css'
1 static file copied to 'C:/root/workspace/mywebapp/src/mywebapp/static/'.
これで、my.cssがc:\ root \ worksheet \ mywebapp \ src \ mywebapp \ css_demo \ static \ css\my.cssにあります。
私の設定では、私は持っています:
STATIC_ROOT = 'C:/root/workspace/mywebapp/src/mywebapp/static/'
STATIC_URL = 'http://localhost/static/'
そして私のurl.pyに私は持っています:
from django.conf.urls.defaults import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = patterns('',
(r'^mywebapp/', include('mywebapp.css_demo.urls')),
)
urlpatterns += staticfiles_urlpatterns()
したがって、私が正しく理解していれば、私のcssは次の場所にあります。
c:\root\workspace\mywebapp\src\mywebapp\css_demo\static\css\my.css
で利用できないはずです:
http://localhost/static/css/my.css
しかし、代わりに私は見る:
Page not found (404)
Request Method: GET
Request URL: http://localhost/static/css/my.css
Using the URLconf defined in mywebapp.urls, Django tried these URL patterns, in this order:
^mywebapp/
The current URL, static/css/my.css, didn't match any of these.
私も試しました:
http://localhost/mywebapp/static/css/my.css
http://localhost/mywebapp/css_demo/static/css/my.css
私はここで一歩を逃していますか?これに関するドキュメントは少し紛らわしいです。 http://docs.djangoproject.com/en/1.3/howto/static-files/ http://docs.djangoproject.com/en/1.3/ref/contrib/staticfiles/
ありがとう!