我正在为我的Django项目添加bootstrap模板。当加载页面并看到内容时,我注意到它没有加载CSS样式,当我尝试编辑文件时,通过识别路径并添加正确的路径,我添加文件夹的文件所在的位置让我感到困惑。 CSS风格是。我很感激有人帮我解决我的问题。
这是原始文件(引导程序模板):
<!DOCTYPE html>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Freelancer - Start Bootstrap Theme</title>
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Theme CSS -->
<link href="css/freelancer.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,700" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic,700italic" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
这是我的setting.py文件:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
LOGIN_REDIRECT_URL = '/'
我的应用(crm)\ urls.py文件:
from django.conf.urls import url, include
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^$', views.HomePageView.as_view()),
url(r'^admin/', admin.site.urls),
url(r'^', include('crm.urls')),
]
和我的views.py文件:
from django.shortcuts import render
from django.views.generic import TemplateView
# Create your views here.
class HomePageView(TemplateView):
def get(self, request, **kwargs):
return render(request, 'crm/index/index.html', context=None)
答案 0 :(得分:0)
href="vendor/font-awesome/css/font-awesome.min.css"
。它将呈现为前缀当前url。例如,当您访问http://www.example.com/aaa/bbb
时。它将呈现为http://www.example.com/aaa/bbb/vendor/font-awesome/css/font-awesome.min.css
。所以你永远不会加载你的css文件。href="/vendor/font-awesome/css/font-awesome.min.css"
。如果它有效,你可以按照下一个提示使其更好。static
。在你的情况下,它看起来像href="{% static "vendor/font-awesome/css/font-awesome.min.css" %}"
。因此它将呈现为http://www.example.com/static/vendor/font-awesome/css/font-awesome.min.css
答案 1 :(得分:0)