【django】【my_blog】详情页面功能

2018-05-07  本文已影响24人  JerichoPH

详情页面功能

完成详情页逻辑

# 文章详情页
def details_page(request, article_id):
    # 读取文章详情
    article_details = models.article.Article.objects.get(pk=article_id)
    return render(request=request, template_name='article/details.html', context={'article_details': article_details})
url(regex=r'^article/details/(?P<article_id>[0-9]+)/$', view=article.details_page, name='article$details_page'),
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文章详情页:{{ article_details.title }}</title>
</head>
<body>
<h2>{{ article_details.title }}</h2>
<h3>{{ article_details.content }}</h3>
</body>
</html>

检查结果,访问:http://localhost:8000/blog/article/details/1/

image

渲染链接

<li><a href="{% url 'blog:article$details_page' article.id %}">{{ article.title }}</a></li>

检查结果,访问:http://localhost:8000/blog/article/index/

image
上一篇 下一篇

猜你喜欢

热点阅读