用Get方法实现文章分类功能
来源:互联网 发布:node.js spring 编辑:程序博客网 时间:2024/06/08 01:20
开发顺序(TMVUT)
Model层需要多少数据字段?
View层根据什么请求,返回什么结果?
Template层如何与用户交互?
M
from django.db import models# Create your models here.class People(models.Model): name = models.CharField(null=True, blank=True,max_length=200) job = models.CharField(null=True, blank=True, max_length=200) def __str__(self): return self.nameclass Aritcle(models.Model):#新增 headline = models.CharField(null=True, blank=True,max_length=500)#新增 content = models.TextField(null=True, blank=True)#新增 TAG_CHOICES = ( ('tech', 'Tech'), ('life','Life'), ) tag = models.CharField(null=True, blank=True, max_length=5, choices=TAG_CHOICES) def __str__(self): return self.headline
C:\Users\Administrator\Desktop\standardweb\firstsite>python manage.py makemigrationsMigrations for 'firstapp': firstapp\migrations\0003_aritcle_tag.py - Add field tag to aritcleC:\Users\Administrator\Desktop\standardweb\firstsite>python manage.py migrateOperations to perform: Apply all migrations: admin, auth, contenttypes, firstapp, sessionsRunning migrations: Applying firstapp.0003_aritcle_tag... OKC:\Users\Administrator\Desktop\standardweb\firstsite>python manage.py runserverPerforming system checks...
V
from django.shortcuts import render, HttpResponsefrom firstapp.models import People, Aritclefrom django.template import Context, Template# Create your views here.def index(request): print(request) print('==='*30) print(dir(request)) print('==='*30) print(type(request)) queryset = request.GET.get('tag') if queryset: article_list = Aritcle.objects.filter(tag=queryset) else: article_list = Aritcle.objects.all()#变量article_list储存Article所有的文章 context = {}#新建字典 context['article_list'] = article_list #字典context中的article_list键(html中通过检索键提取文章内容)对应article_list变量的值 index_page = render(request, 'first_web_2.html', context) return index_page
T
{% load staticfiles %}<!DOCTYPE html><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"> h1 { font-family:'Oswald', sans-serif!important; font-size:40px; } body { font-family: 'Raleway', sans-serif; } p { font-family: 'Raleway', sans-serif; font-size:18px; } .ui.vertical.segment.masthead { height: 300px; background-image: url({% static 'images/star_banner.jpg' %}); background-size: cover; background-position: 100% 80%; } .ui.container.segment { width: 800px; } .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; } </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="#"> <h1 class="ui header"> {{ article.headline }} </h1> </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>
阅读全文
0 0
- 用Get方法实现文章分类功能
- 05 使用Get方法实现网页分类功能
- OpenCms 中实现文章分类功能
- php实现相关文章功能代码方法
- Blog文章分类方法
- 利用分类实现功能
- 文章列表加上编辑分类功能了!
- Android get/ post 方法 传递网络数据 -简单的翻译功能实现(GET)
- ALV分类合计功能实现
- HttpURLConnection-Get方法实现
- 用递归的方法实现无限分类
- asp实现文章摘要功能
- django 实现文章跳转功能
- 文章编辑实现分页功能
- 用CASE WHEN实现sqlserver数据库的分类汇总功能
- ecshop调用指定文章分类的方法
- ECSHOP2.61添加首页文章分类方法
- 利用datalist实现文章的分类查看
- fragment异常android.app.Fragment$InstantiationException: Unable to instantiate fragment
- deep learning index
- Handler内存泄漏分析及解决
- groovy if判断
- Html5斜45度地图+3D模型ARPG系列教程(6)-- 寻路算法及平滑处理
- 用Get方法实现文章分类功能
- eclipse安装插件的几种方式
- 关于浏览器
- 兴奋剂检查(Vijos-1426)
- Golang精编100题
- 初识mina
- nginx的安装与使用
- rabbitMq-TTL、DLX实现延时队列
- 我与python约个会:25. 企业级开发基础6:面向对象特征(继承)