【问题标题】:Formatting Issues With Django & BootstrapDjango 和 Bootstrap 的格式化问题
【发布时间】: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


【解决方案1】:

好的,你的视图对真正的请求上下文一无所知。

请使用类似于

的东西
from django.template.response import TemplateResponse
...
return TemplateResponse(request, "Details_Main.html", {
    "object": some_object,   # only if you have something to add into the context. otherwise leave the dictionary empty.
})

【讨论】:

  • 啊,好吧,在我阅读的文档或指南中,没有任何地方提到过修改您的视图。 :S 不管怎样,我们越来越近了。该 URL 现在显示为:127.0.0.1:8000/static/bootstrap/css/bootstrap.css" rel="stylesheet"> 还更新了主帖以显示我的更改...
猜你喜欢
  • 2021-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-02
相关资源
最近更新 更多