You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tentest/doc/DjangoBlog/blog/urls.py

91 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from django.urls import path
from django.views.decorators.cache import cache_page
from . import views
# mk:定义应用的命名空间用于URL反向解析时区分不同应用的同名URL
app_name = "blog"
# mk:URL模式配置列表定义了博客应用的所有路由规则
urlpatterns = [
# mk:首页路由,显示文章列表,默认第一页
path(
r'',
views.IndexView.as_view(),
name='index'),
# mk:分页首页路由,显示指定页码的文章列表
path(
r'page/<int:page>/',
views.IndexView.as_view(),
name='index_page'),
# mk:文章详情页路由通过年月日和文章ID访问具体文章
path(
r'article/<int:year>/<int:month>/<int:day>/<int:article_id>.html',
views.ArticleDetailView.as_view(),
name='detailbyid'),
# mk:分类详情页路由,通过分类名称访问该分类下的所有文章
path(
r'category/<slug:category_name>.html',
views.CategoryDetailView.as_view(),
name='category_detail'),
# mk:分类详情页分页路由,通过分类名称和页码访问该分类下指定页码的文章
path(
r'category/<slug:category_name>/<int:page>.html',
views.CategoryDetailView.as_view(),
name='category_detail_page'),
# mk:作者详情页路由,通过作者名称访问该作者发布的所有文章
path(
r'author/<author_name>.html',
views.AuthorDetailView.as_view(),
name='author_detail'),
# mk:作者详情页分页路由,通过作者名称和页码访问该作者发布指定页码的文章
path(
r'author/<author_name>/<int:page>.html',
views.AuthorDetailView.as_view(),
name='author_detail_page'),
# mk:标签详情页路由,通过标签名称访问带有该标签的所有文章
path(
r'tag/<slug:tag_name>.html',
views.TagDetailView.as_view(),
name='tag_detail'),
# mk:标签详情页分页路由,通过标签名称和页码访问带有该标签的指定页码文章
path(
r'tag/<slug:tag_name>/<int:page>.html',
views.TagDetailView.as_view(),
name='tag_detail_page'),
# mk:归档页面路由缓存1小时显示所有文章的归档信息
path(
'archives.html',
cache_page(
60 * 60)(
views.ArchivesView.as_view()),
name='archives'),
# mk:友情链接页面路由,显示所有友情链接
path(
'links.html',
views.LinkListView.as_view(),
name='links'),
# mk:文件上传路由,处理文件上传请求
path(
r'upload',
views.fileupload,
name='upload'),
# mk:清除缓存路由,处理清除缓存的请求
path(
r'clean',
views.clean_cache_view,
name='clean'),
]