Django教程-带有 Bootstrap 的 Django
Django教程-带有 Bootstrap 的 Django
gh_1d7504e4dee1
回复:python,领取Python面试题。分享Python教程,Python架构师教程,Python爬虫,Python编程视频,Python脚本,Pycharm教程,Python微服务架构,Python分布式架构,Pycharm注册码。
Bootstrap 是一个用于在 Web 应用程序中创建用户界面的框架。它提供了css、js和其他工具来帮助创建所需的界面。
在Django中,我们可以使用bootstrap来创建更加用户友好的应用程序。
为了实现bootstrap,我们需要遵循以下步骤。
1.下载引导程序
访问官方网站 https://getbootstrap.com 将 bootstrap 下载到本地计算机。它是一个zip文件,解压它并看到它包含两个文件夹。
资源分享
2. 创建目录
在创建的应用程序中创建一个名为static 的目录,并将 css 和 jss 文件夹放入其中。这些文件夹包含大量文件,请参见屏幕截图。
3. 创建模板
首先在应用程序内创建一个 templates 文件夹,然后创建一个 index.htm 文件来实现(链接)引导 css 和 js 文件。
4. 加载Boostrap
将引导文件加载到静态文件夹中。使用以下代码。
{% load staticfiles %}
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
>
Title
</
title
>
{% load staticfiles %}
<
link
href
=
"{% static ’css/bootstrap.min.css’ %}"
>
<
script
src
=
"{% static ’bootstrap.min.js’ %}"
>
</
script
>
<
script
>
alert();
</
script
>
</
head
>
<
body
>
</
body
>
</
html
>
假设,如果我们不使用 bootstrap,我们的 html 登录看起来像这样:
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
>
login
</
title
>
</
head
>
<
body
>
<
form
action
=
"/save"
method
=
"post"
>
<
div
class
=
"form-group"
>
<
label
for
=
"email"
>
Email address:
</
label
>
<
input
type
=
"email"
class
=
"form-control"
id
=
"email"
>
</
div
>
<
div
class
=
"form-group"
>
<
label
for
=
"pwd"
>
Password:
</
label
>
<
input
type
=
"password"
class
=
"form-control"
id
=
"pwd"
>
</
div
>
<
div
class
=
"checkbox"
>
<
label
>
<
input
type
=
"checkbox"
>
Remember me
</
label
>
</
div
>
<
button
type
=
"submit"
class
=
"btn btn-primary"
>
Submit
</
button
>
</
form
>
</
body
>
</
html
>
加载引导文件后。我们的代码如下所示:
// 索引.html
<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
title
>
login
</
title
>
{% load staticfiles %}
<
link
href
=
"{% static ’css/bootstrap.min.css’ %}"
rel
=
"stylesheet"
>
<
script
src
=
"{% static ’js/bootstrap.min.js’ %}"
>
</
script
>
</
head
>
<
body
>
<
form
action
=
"/save"
method
=
"post"
>
<
div
class
=
"form-group"
>
<
label
for
=
"email"
>
Email address:
</
label
>
<
input
type
=
"email"
class
=
"form-control"
id
=
"email"
>
</
div
>
<
div
class
=
"form-group"
>
<
label
for
=
"pwd"
>
Password:
</
label
>
<
input
type
=
"password"
class
=
"form-control"
id
=
"pwd"
>
</
div
>
<
div
class
=
"checkbox"
>
<
label
>
<
input
type
=
"checkbox"
>
Remember me
</
label
>
</
div
>
<
button
type
=
"submit"
class
=
"btn btn-primary"
>
Submit
</
button
>
</
form
>
</
body
>
</
html
>
现在,我们的登录表单看起来好多了。这就是引导程序的优点。
最后,项目结构如下所示。
-
Julia 将取代 Python?TIOBE 8 月榜单发布!
-
Django教程-使用 Django 视图设计和生成 PDF 文件
-
很炫酷,我可能要抛弃Chrome了...
-
2023年血糖新标准公布,不是3.9-6.1,快来看看你的血糖正常吗? 2023-02-07
-
2023年各省最新电价一览!8省中午执行谷段电价! 2023-01-03
-
GB 55009-2021《燃气工程项目规范》(含条文说明),2022年1月1日起实施 2021-11-07
-
PPT导出高分辨率图片的四种方法 2022-09-22
-
2023年最新!国家电网27家省级电力公司负责人大盘点 2023-03-14
-
全国消防救援总队主官及简历(2023.2) 2023-02-10
-
盘点 l 中国石油大庆油田现任领导班子 2023-02-28
-
我们的前辈!历届全国工程勘察设计大师完整名单! 2022-11-18
-
关于某送变电公司“4·22”人身死亡事故的快报 2022-04-26
