
Django入门与实践:七、博客文章页开发
发布日期:2021-05-07 01:04:25
浏览次数:12
分类:技术文章
本文共 910 字,大约阅读时间需要 3 分钟。
页面内容:
标题
文章内容
修改文章按钮(超链接)
myblog/blog/views.py:
from django.shortcuts import renderfrom django.http import HttpResponsefrom . import models# Create your views here.def index(request): #return HttpResponse("Hello world!") #return render(request, 'index.html', {'hello': 'hello, blog!'}) articles = models.Article.objects.all() return render(request, "blog/index.html", {"articles": articles})def article_page(request, article_id): article = models.Article.objects.get(pk=article_id) return render(request, 'blog/article_page.html', {'article': article})
myblog/blog/templates/blog/article_page.html:
article page { {article.title}}
{ {article.content}}
myblog/blog/urls.py:
from django.urls import path, re_pathfrom . import viewsurlpatterns = [ path('index/', views.index), re_path('^article/(?P[0-9]+)/$', views.article_page),]
注:正则中的组名必须和参数名一致!
浏览器中输入:即可访问。
发表评论
最新留言
哈哈,博客排版真的漂亮呢~
[***.90.31.176]2025年03月12日 21时17分12秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
JavaScript学习手册(45)
2019-03-03
【纪中2020.5.06日】模拟赛题解
2019-03-03
eclipse中server location灰色解决
2019-03-03
idea 写web项目图片不显示
2019-03-03
SVM多类识别
2019-03-03
svn 撤销已提交的错误修改
2019-03-03
算法工程师数学理论提高札记(improving)
2019-03-03
Android网络优化--精准获取流量消耗
2019-03-03
VTK:IO之WriteVTI
2019-03-03
VTK:图片之ImageExport
2019-03-03
VTK:图片之ImageMathematics
2019-03-03
VTK:图片之ImageOrientation
2019-03-03
VTK:图片之ImageToPolyDataFilter
2019-03-03
VTK:图片之ImageToStructuredPoints
2019-03-03
VTK:图片之ImageValueRange
2019-03-03
VTK:图片之RGBToHSV
2019-03-03
VTK:隐式函数之ImplicitSphere
2019-03-03
VTK:InfoVis之DelimitedTextReader
2019-03-03
数据结构与算法学习1-----稀疏数组
2019-03-03
Java转换xml格式时间 (yyyy-MM-ddTHH:mm:ss.SSSZ)
2019-03-03