私は非常に新しくdjango
、何日もチュートリアルを行ってきました.djangoを使用して小さなWebサイトの構築を開始しcss
、必要なすべての設定をsettings.py
ファイルに配置してファイルを提供しようとしました. 残念ながら、私のコードは css ファイルを提供できません。つまり、css ファイルを提供するという概念が機能していません。私はたくさんグーグルで検索し、djangoのメインドキュメントチュートリアルを調べ、それらに従って変更を加えましたが、まだ機能しないのでSO
、コード全体を以下に貼り付けました
プロジェクトフォルダの構造
personnel_blog
|____personnel_blog
|____manage.py |
|____media
|____static
| |____css
| |____personnel_blog_hm.css
|____template
| |____home_page.html
|____settings.py
|____urls.py
|____views.py
|____wsgi.py
私のsettings.pyファイル設定の一部を以下に示します
設定.py
import os
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
MEDIA_ROOT = os.path.join(PROJECT_DIR,'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(PROJECT_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_DIR,'static'),
# 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_DIRS = (
os.path.join(PROJECT_DIR,'templates')
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
)
urls.py
from django.conf.urls.defaults import *
from django.conf import settings
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'personnel_blog.views.home_page'),
url(r'^admin/', include(admin.site.urls)),
)
if settings.DEBUG:
urlpatterns += patterns('',
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': settings.MEDIA_ROOT, 'show_indexes': True }),
url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT, 'show_indexes': True }),
)
ビュー.py
from django.shortcuts import render_to_response
def home_page(request):
return render_to_response("home_page.html")
home_page.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}css/personnel_blog_hm.css" type="text/css">
</head>
<body>
<p>Hello !</p>
<a href="/" target="_top">Home</a>
</body>
</html>
person_blog_hm.css
body { background-color:green; }
p {color:blue;background-color:green;padding-left:20px;}
上記は私のコードですが、settigns.pyファイルまたは他のpyファイルの何が問題なのか教えてください。
上記のコードで他の追加設定を行う必要があるかどうか
誰でも私のコードを調整し、必要な変更を加えて、私が前進してWebデザインの最初の一歩を踏み出すことができます..... :)