我在構建一個chatbot應用程序。前端的CSS沒有通過使用django的靜態數據加載來加載。使用django加載CSS返回404
路徑CSS是 - C:\文檔\ Django_Workspace \ BOT \模板\靜\ bot.css
路徑HTML是 - C:\文檔\ Django_Workspace \ BOT \模板\ index.html在
我在設置中添加STATIC_URL文件作爲
STATIC_URL = '/static/'
的HTML鏈接標記看起來像
{% load static %}
<head>
<meta charset="UTF-8">
<title>bot</title>
<link rel="stylesheet" type="text/css" href="{% static "bot.css" %}" />
</head>
我Urls.py看起來像
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
這是我如何呈現HTML頁面
from django.http import HttpResponse
from django.template import loader
from .models import User_Message
def index(request):
template = loader.get_template('index.html')
return HttpResponse(template.render())
誰能幫助。我甚至嘗試在html標記中硬編碼css文件的路徑。但是,這不起作用
謝謝,這對我有效。 – Gautam