1
现在我试图在我的Django Hello World程序中使用一些基本的CSS。我可以显示“Hello World”,但CSS效果不起作用。目前这是我在我的主要网址:试图在Django Hello World中使用CSS
from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'',include('firstapp.urls')),
]
这就是我在我的应用程序的URL。
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
这是我的观点文件。
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
context = {"variable":"Hello World"}
return render(request, "base.html", context)
我base.html文件文件
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
<link rel='stylesheet' href='{% static "css/base.css" %}'/>
</head>
<html>
<p>{{ variable }}</p>
<script src="{% static "base.js'" %}"></script>
</body>
</html>
而且我base.css文件。
h1 {
color: 00FFFF;
}
最后,我在设置文件的底部添加了这段代码。
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(os.path.dirname(BASE_DIR), "static_cdn")
理想情况下,页面应该在青色用的“Hello World”显示...不幸的是它只是显示的“Hello World”在正常的黑色文本。有人知道为什么吗?