复习:博客站点

<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
<meta charset="utf-8">
<title>first web</title>
<link rel="stylesheet" href="{% static 'css/semantic.css'%}" media="screen" title="no title" charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Oswald|Raleway" rel="stylesheet">
<style type="text/css">
/*封面图部分样式如下*/
.ui.vertical.segment.masthead {
height: 300px;
background: url("{% static 'images/star_banner.jpg'%}");
background-size: cover;
background-position: 100% 80%;
} .ui.center.aligned.header.blogslogon {
margin-top: 40px;
}
.ui.center.aligned.header.blogslogon p {
margin-top: 10px;
color: white;
font-size: 10px;
}
/*菜单栏部分样式如下*/
.ui.container.nav {
width: 500px;
} /*菜单栏部分样式如下*/
.ui.container.vertical.segment {
width: 800px;
} h2 {
font-family:'Oswald', sans-serif!important;
font-size:40px;
} p {
font-family: 'Raleway', sans-serif;
font-size:18px;
}
</style>
</head>
<body>
<!-- 封面图部分如下 -->
<div class="ui inverted vertical segment masthead">
<h1 class="ui center aligned header blogslogon" style="font-size:50px;font-family: 'Raleway', sans-serif!important;">
Bloger
<p class="ui sub header">
everyone has a story to tell
</p>
</h1>
</div>
<!-- 菜单栏部分如下 -->
<div class="ui container nav">
<div class="ui borderless text three item menu ">
<div class="ui simple dropdown item">
Categories
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="">life</a>
<a class="item" href="">tech</a>
</div>
</div>
<a class="item">
Popular
</a>
<a class="item">
About
</a>
</div>
</div>
<div class="ui divider"></div>
<!-- 文章内容部分如下 -->
<div class="ui vertical segment">
{% for article in article_list%}
<div class="ui container vertical segment">
<a href="#">
<h2 class="ui header">
{{ article.headline }}
</h2>
</a>
<i class="icon grey small unhide">10,000</i>
<p>
{{ article.content|truncatewords:100 }}
<a href="#">
<i class="angle tiny double grey right icon">READMORE</i>
</a>
</p>
<div class="ui mini tag label">
life
</div>
</div>
{% endfor %} </div>
<!-- 页尾部分如下 -->
<div class="ui inverted vertical very padded segment">
Mugglecoding®
</div>
</body>
</html>

1.GET方法传递参数

         

2.开发过程的三个问题(从后向前思考)

  1. Model层:需要多少个数据字段

  2. View层:根据什么请求,返回什么结果

  3. Template层:如何与用户进行交互?

(2)开发流程

  • T  需要看到数据的网页

  • M 做数据

  • V 视图模型

  • U url地址

  • T 调整网页



1.Model层

  (1)添加tag标签

  • choices 选项

           

    TAG_CHOICES = (
('tech','Tech'), #值:名字
('life','Life'),
)
tag = models.CharField(null=True,blank=True,max_length=5, choices=TAG_CHOICES)

 

  (2)更新数据库到后台

PS C:\Users\Administrator\Desktop\root\firstsite> python.exe .\manage.py makemigrations

PS C:\Users\Administrator\Desktop\root\firstsite> python.exe .\manage.py migrate

PS C:\Users\Administrator\Desktop\root\firstsite> python.exe .\manage.py runserver

  

  (3)启动服务器,后台查看tag标签

     

  

2. View层

(1)认识request请求参数?

    

    

    (2)通过GET方法获取tag对应的值

    

    

    

  (3)判断request请求,通过Get方法得到的数据,进行判断

    

  • http://127.0.0.1:8000/index/?tag=tech

     

  

  • http://127.0.0.1:8000/index/?tag=life

    

    

  (4)views.py的index视图代码

def index(request):
print(request)
print("==="*30)
print(dir(request))
print("==="*30)
print(type(request)) queryset = request.GET.get('tag')
print(queryset) if queryset:
article_list = Aritcle.objects.filter(tag=queryset) #过滤器
else:
article_list = Aritcle.objects.all() #获取Article数据库所有的数据 context = {}
context['article_list'] = article_list
index_page = render(request,'firstweb.html',context)
return index_page

  

3.Template层:如何与用户交互?

  (1)a标签跳转url

  (2)小修改:模板变量

    

    

    (3) html代码

  <!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
<meta charset="utf-8">
<title>first web</title>
<link rel="stylesheet" href="{% static 'css/semantic.css'%}" media="screen" title="no title" charset="utf-8">
<link href="https://fonts.googleapis.com/css?family=Oswald|Raleway" rel="stylesheet">
<style type="text/css">
/*封面图部分样式如下*/
.ui.vertical.segment.masthead {
height: 300px;
background: url("{% static 'images/star_banner.jpg'%}");
background-size: cover;
background-position: 100% 80%;
} .ui.center.aligned.header.blogslogon {
margin-top: 40px;
}
.ui.center.aligned.header.blogslogon p {
margin-top: 10px;
color: white;
font-size: 10px;
}
/*菜单栏部分样式如下*/
.ui.container.nav {
width: 500px;
} /*菜单栏部分样式如下*/
.ui.container.vertical.segment {
width: 800px;
} h2 {
font-family:'Oswald', sans-serif!important;
font-size:40px;
} p {
font-family: 'Raleway', sans-serif;
font-size:18px;
}
</style>
</head>
<body>
<!-- 封面图部分如下 -->
<div class="ui inverted vertical segment masthead">
<h1 class="ui center aligned header blogslogon" style="font-size:50px;font-family: 'Raleway', sans-serif!important;">
Bloger
<p class="ui sub header">
everyone has a story to tell
</p>
</h1>
</div>
<!-- 菜单栏部分如下 -->
<div class="ui container nav">
<div class="ui borderless text three item menu ">
<div class="ui simple dropdown item">
Categories
<i class="dropdown icon"></i>
<div class="menu">
<a class="item" href="?tag=life">life</a>
<a class="item" href="?tag=tech">tech</a>
</div>
</div>
<a class="item">
Popular
</a>
<a class="item">
About
</a>
</div>
</div>
<div class="ui divider"></div>
<!-- 文章内容部分如下 -->
<div class="ui vertical segment">
{% for article in article_list%}
<div class="ui container vertical segment">
<a href="#">
<h2 class="ui header">
{{ article.headline }}
</h2>
</a>
<i class="icon grey small unhide">10,000</i>
<p>
{{ article.content|truncatewords:100 }}
<a href="#">
<i class="angle tiny double grey right icon">READMORE</i>
</a>
</p>
<div class="ui mini tag label">
{{ article.tag }}
</div>
</div>
{% endfor %} </div>
<!-- 页尾部分如下 -->
<div class="ui inverted vertical very padded segment">
Mugglecoding®
</div>
</body>
</html>

最新文章

  1. WPF 点击Calendar后,需要点击两次按钮
  2. 使用UltraISO制作U盘启动盘——转载
  3. Spring的起源和背景
  4. IOS 开发中判断NSString是否为空字符
  5. POJ1155 - TELE(树形DP)
  6. JTree实例
  7. iOS UITableView的多选
  8. linux系统连接的概念及删除原理
  9. Spark RPC框架源码分析(二)RPC运行时序
  10. 快速幂 ,快速幂优化,矩形快速幂(java)
  11. Spring Cloud Greenwich 正式发布,Hystrix 即将寿终正寝。。
  12. [Flutter] 写第一个 Flutter app,part1 要点
  13. UVa - 10339
  14. svn使用openldap验证apache访问方式
  15. mysql性能分析show profile/show profiles
  16. MySQL之UNDO及MVCC、崩溃恢复
  17. 如何使用Java Enum
  18. jquery获取点击控件的绝对位置简单实例
  19. 【RF库Collections测试】Dictionary Should Contain Key
  20. javascript全局方法与变量

热门文章

  1. springboot:ajax跨域请求解决方案
  2. Spark job执行流程消息图
  3. js从入门到精通到深入到就业
  4. 【js基础修炼之路】— 深入浅出理解闭包
  5. Uva 12169 不爽的裁判 模运算
  6. android获取传感器数据
  7. 简单介绍Spring是什么?
  8. java的四个元注解 @Retention @Target @Document @Inherited
  9. 八数码(map版)
  10. C++编程经验总结1