Django入门指南-第9章:静态文件设置(完结)
#下一步是告诉Django在哪里可以找到静态文件。打开settings.py,拉到文件的底部,在STATIC_URL后面添加以下内容:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
<!--现在我们必须在模板中加载静态文件(Bootstrap CSS文件):-->
<!--只要记住但凡是引用到CSS,JavaScript或图片文件的地方就是要{% load static %}.-->
<!--templates/home.html-->
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Boards</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
</head>
<body>
<h1>Boards</h1>
<table border="1">
<thead>
<tr>
<th>Board</th>
<th>Posts</th>
<th>Topics</th>
<th>Last Post</th>
</tr>
</thead>
<tbody>
{% for board in boards %}
<tr>
<td>{{ board.name }}<br>
<small style="color: #888">{{ board.description }}</small>
</td>
<td>0</td>
<td>0</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
<!--现在我们可以编辑模板,以利用Bootstrap CSS:-->
{% load static %}<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Boards</title>
<link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
</head>
<body>
<div class="container">
<ol class="breadcrumb my-4">
<li class="breadcrumb-item active">Boards</li>
</ol>
<table class="table">
<thead class="thead-inverse">
<tr>
<th>Board</th>
<th>Posts</th>
<th>Topics</th>
<th>Last Post</th>
</tr>
</thead>
<tbody>
{% for board in boards %}
<tr>
<td>{{ board.name }}
<small class="text-muted d-block">{{ board.description }}</small>
</td>
<td class="align-middle">0</td>
<td class="align-middle">0</td>
<td></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</body>
</html>
Django入门指南-第9章:静态文件设置(完结)的更多相关文章
- Django入门指南-第10章:Django Admin 介绍(完结)
在浏览器中打开该URL:http://127.0.0.1:8000/admin/ 我们可以检查一切是否正常,打开URL http://127.0.0.1:8000 我们首先创建一个管理员帐户: pyt ...
- Django入门指南-第8章:第一个测试用例(完结)
python manage.py test python manage.py test --verbosity=2 # boards/tests.py from django.core.urlreso ...
- Django入门指南-第7章:模板引擎设置(完结)
http://127.0.0.1:8000/ <!--templates/home.html--> <!DOCTYPE html> <html> <head& ...
- Django入门指南-第6章:第一个视图函数(完结)
http://127.0.0.1:8000/ # boards/views.py from django.http import HttpResponse from .models import Bo ...
- django 简易博客开发 3 静态文件、from 应用与自定义
首先还是贴一下源代码地址 https://github.com/goodspeedcheng/sblog 上一篇博客我们介绍了 django 如何在views中使用templates以及一些常用的数 ...
- 基于 Vue.js 之 iView UI 框架非工程化实践记要 使用 Newtonsoft.Json 操作 JSON 字符串 基于.net core实现项目自动编译、并生成nuget包 webpack + vue 在dev和production模式下的小小区别 这样入门asp.net core 之 静态文件 这样入门asp.net core,如何
基于 Vue.js 之 iView UI 框架非工程化实践记要 像我们平日里做惯了 Java 或者 .NET 这种后端程序员,对于前端的认识还常常停留在 jQuery 时代,包括其插件在需要时就引 ...
- 完整的Django入门指南学习笔记2
part2: 前沿 在第一节中,我们安装了项目所需要的一切:Python3.6以及在虚拟环境中运行的Django2.0,这部分教程继续在项目上编写代码. 开始写代码前,先讨论下项目的相关背景知识,然后 ...
- 完整的Django入门指南学习笔记7 网页自动翻译
转自[https://simpleisbetterthancomplex.com/series/2017/10/16/a-complete-beginners-guide-to-django-part ...
- Django入门与实践 17-26章总结
Django入门与实践-第17章:保护视图 Django 有一个内置的视图装饰器 来避免它被未登录的用户访问: 现在如果用户没有登录,将被重定向到登录页面: 现在尝试登录,登录成功后,应用程序会跳转到 ...
随机推荐
- 在spring引入log4j(非web项目)
https://blog.csdn.net/u012578322/article/details/78012183 在spring中使用log4j 引入log4j软件包 配置log4j属性 加载log ...
- JDK9-模块化系统
Content 0. 实例 0.1 使用命令行编写和运行模块程序 0.1.1 设置目录 0.1.2 编写源代码 0.1.3 编译 0.1.4 打包模块代码 0.1.5 运行程序 0.2 使用eclip ...
- WP runtime 获取cookie
HttpBaseProtocolFilter httpBaseProtocolFilter = new HttpBaseProtocolFilter(); HttpCookieManager http ...
- request.getParameterMap()获得Map中的数据
今天使用request.getParameterMap()获得Map中的数据时,使用 Map map=request.getParameterMap(); i ...
- How to Pronounce EVERY
How to Pronounce EVERY Share Tweet Share Tagged With: 2-Syllable Everybody should learn the word ‘ev ...
- Haskell语言学习笔记(30)MonadCont, Cont, ContT
MonadCont 类型类 class Monad m => MonadCont m where callCC :: ((a -> m b) -> m a) -> m a in ...
- 3.3 JSP内置对象概述
1.request 1.1 request获取页面传来的参数,参数通过浏览器网址和后面添加?的方式传达. 传参:”show.jsp?id=001” 获取参数:request.getParameter( ...
- Mysql 内部默认排序
mysql默认的排序: https://forums.mysql.com/read.php?21,239471,239688#msg-239688 Do not depend on order whe ...
- http头解释
<---响应头---> 长连接: Connection: keep-alive 开启长连接 ---- connection 英 [kəˈnekʃn]连接 ...
- 第八章 高级搜索树 (a3)伸展树:算法实现