在我的Django项目有一些神秘的(至少对我来说作为一个beinner)输出在我的开发环境中工作时,我不明白。 我想有一个基本模板,其中包括在静态媒体文件夹的样式表......到目前为止是这种情况......但只是地址http://localhost/所有其他URL都从基本模板继承的模板。Django模板继承不提供css?
现在http://localhost/的样式表看起来不错...如果我去http://localhost/hello/包含的样式表有一个完整的html DOM结构体,doctype等。为什么?他莫名其妙地解析HTML的网站,而不是采取CSS文件...
这里我的代码:任何想法?
urls.py:
from django.views.static import *
from django.conf import settings
admin.autodiscover()
urlpatterns = patterns('',
('^$',home_view),
('^hello/$', hello),
(r'^admin/', include(admin.site.urls)),
('^useragent/$',ua_display_good1),
(r'^media/(?P<path>.*)$', 'django.views.static.serve',
)
views.py
from django.http import HttpResponse
from django.shortcuts import render_to_response
def hello(request):
pagetitle = "Hello World"
return render_to_response('hello.tpl', {'pagetitle': pagetitle})
def home_view(request):
pagetitle = "Something"
return render_to_response('home.tpl', {'pagetitle': pagetitle})
def ua_display_good1(request):
try:
ua = request.META['REMOTE_ADDR']
except KeyError:
ua = 'unknown'
return render_to_response('base.tpl',{'ageone': ua})
基本模板:
<!DOCTYPE html>
<html lang="de">
<meta name="description=" content="{{metadescription}}">
<head>
<link rel="stylesheet" type="text/css" href="media/style.css">
<title>{% block title %}{{pagetitle}}{% endblock %}</title>
</head>
<body>
<h1>{% block h1 %}{{ageone}}{% endblock %}</h1>
{% block content %}{% endblock %}
{% block footer %}{% include "footer.tpl" %}
{% endblock %}
</body>
</html>
你好模板:
{% extends "base.tpl" %}
{% block h1 %}Home{% endblock %}
{% block content %}Welcome{% endblock %}
现在我明白了谢谢你! – Jurudocs