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/djangoblog/urls.py

113 lines
5.4 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.

"""djangoblog URL Configuration
Django博客项目的URL配置文件
The `urlpatterns` list routes URLs to views. For more information please see:
`urlpatterns`列表用于将URL路由到对应的视图。更多信息请参考
https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
函数视图示例:
1. Add an import: from my_app import views
1. 导入视图from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
2. 添加URL到urlpatternsurl(r'^$', views.home, name='home')
Class-based views
类视图示例:
1. Add an import: from other_app.views import Home
1. 导入类视图from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
2. 添加URL到urlpatternsurl(r'^$', Home.as_view(), name='home')
Including another URLconf
包含其他URL配置示例
1. Import the include() function: from django.conf.urls import url, include
1. 导入include()函数from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
2. 添加URL到urlpatternsurl(r'^blog/', include('blog.urls'))
"""
# wr导入Django配置
from django.conf import settings
#wr 导入国际化URL工具用于生成带语言前缀的URL
from django.conf.urls.i18n import i18n_patterns
#wr 导入静态文件URL配置工具
from django.conf.urls.static import static
# wr导入站点地图视图
from django.contrib.sitemaps.views import sitemap
# wr导入URL路径配置工具
from django.urls import path, include
from django.urls import re_path # wr兼容正则表达式的URL配置
#wr 导入Haystack搜索视图工厂
from haystack.views import search_view_factory
#wr 导入JSON响应工具
from django.http import JsonResponse
import time #wr 时间模块,用于健康检查的时间戳
from blog.views import EsSearchView
#wr 导入自定义管理员站点
from djangoblog.admin_site import admin_site
#wr 导入ElasticSearch搜索表单
from djangoblog.elasticsearch_backend import ElasticSearchModelSearchForm
#wr 导入RSS订阅源
from djangoblog.feeds import DjangoBlogFeed
#wr 导入站点地图配置类
from djangoblog.sitemap import (
ArticleSiteMap, CategorySiteMap,
StaticViewSitemap, TagSiteMap, UserSiteMap
)
#wr 站点地图配置:定义不同类型页面的站点地图
sitemaps = {
'blog': ArticleSiteMap, #wr文章页面站点地图
'Category': CategorySiteMap, #wr 分类页面站点地图
'Tag': TagSiteMap, #wr 标签页面站点地图
'User': UserSiteMap, #wr 用户页面站点地图
'static': StaticViewSitemap # wr静态页面如首页站点地图
}
# wr错误页面处理配置指定对应错误码的处理视图
handler404 = 'blog.views.page_not_found_view' # wr404页面不存在
handler500 = 'blog.views.server_error_view' # wr500服务器内部错误
handle403 = 'blog.views.permission_denied_view' # wr403权限拒绝
def health_check(request):
"""
wr健康检查接口
用于监控服务是否正常运行(如容器化部署中的存活探针)
"""
return JsonResponse({
'status': 'healthy', #wr 健康状态标识
'timestamp': time.time() # wr当前时间戳用于验证响应时效性
})
# wr基础URL配置不依赖语言前缀的URL
urlpatterns = [
path('i18n/', include('django.conf.urls.i18n')), # wr国际化配置入口语言切换等
path('health/', health_check, name='health_check'), # 健康检查接口
]
# wr国际化URL配置带语言前缀的URL如/en/blog/、/zh/blog/
urlpatterns += i18n_patterns(
re_path(r'^admin/', admin_site.urls), # wr自定义管理员后台URL
re_path(r'', include('blog.urls', namespace='blog')), # wr博客主应用URL命名空间blog
re_path(r'mdeditor/', include('mdeditor.urls')), #wr Markdown编辑器URL
re_path(r'', include('comments.urls', namespace='comment')), # wr评论应用URL命名空间comment
re_path(r'', include('accounts.urls', namespace='account')), #wr 用户账户应用URL命名空间account
re_path(r'', include('oauth.urls', namespace='oauth')), #wr 第三方登录应用URL命名空间oauth
# wr站点地图XML文件URL搜索引擎会抓取此文件
re_path(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps},
name='django.contrib.sitemaps.views.sitemap'),
re_path(r'^feed/$', DjangoBlogFeed()), # wrRSS订阅源URL/feed/
re_path(r'^rss/$', DjangoBlogFeed()), #wr RSS订阅源URL/rss/与feed等价
# wr搜索功能URL使用自定义的ElasticSearch搜索视图和表单
re_path('^search', search_view_factory(view_class=EsSearchView, form_class=ElasticSearchModelSearchForm),
name='search'),
re_path(r'', include('servermanager.urls', namespace='servermanager')), #wr 服务器管理应用URL
re_path(r'', include('owntracks.urls', namespace='owntracks')), # wr位置追踪应用URL
prefix_default_language=False #wr 不使用默认语言前缀(如默认语言为中文时,不强制添加/zh/
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) #wr 静态文件URL配置
#wr 开发环境下的媒体文件URL配置生产环境通常由Web服务器处理
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)