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」在正常的黑色文本。有人知道爲什麼嗎?