【发布时间】:2013-01-26 17:12:01
【问题描述】:
我刚刚在我的 Django 站点上安装了 Bootstrap。我已按照几个教程的说明进行操作。
但是,当我通过 Django 服务器查看页面时,它只是基于文本的,没有任何格式。 离线查看同一个页面(只是在网络浏览器中打开)并且该页面具有所有 Bootstrap 格式。
所以,在线查看格式似乎不起作用。 我已经按照这里的教程:'https://docs.djangoproject.com/en/dev/howto/static-files/'
但是还是没有运气。
我的模板:
{% load staticfiles %}
<link href="{{ STATIC_URL }}bootstrap/css/bootstrap.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
}
</style>
</head>
我的设置:
STATIC_ROOT = 'C:/Users/Dummy/Documents/Django/ParkManager/static/'
STATIC_URL = 'http://127.0.0.1:8000/static/'
....
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'Parks',
'django_admin_bootstrapped',
'django.contrib.staticfiles',
我的看法
from django.template.response import TemplateResponse
def Search_Page(request):
return TemplateResponse(request, 'Details_Main.html', {'request':'index'})
【问题讨论】:
-
STATIC_URL 必须是“http://...”或“/static/whatever”形式的 URL。在浏览器中生成的页面 html 源代码是什么?
-
啊,确实有道理。我假设以下内容:127.0.0.1:8000/ParkManager/ParkManager/static?在我的网络浏览器中,它没有附加 URL:
-
通常 STATIC_URL 类似于 '/static'。但是您的模板没有使用 STATIC_URL,正如您在 标记的 href 中看到的那样。也许您的模板缺少请求上下文。你如何在你的视图中调用模板?可以发表一下你的看法吗?
-
好的,谢谢 刚刚添加了与此页面相关的视图
标签: django twitter-bootstrap django-templates