|
|
#gq:
|
|
|
"""djangoblog URL Configuration
|
|
|
|
|
|
The `urlpatterns` list routes URLs to views. For more information please see:
|
|
|
https://docs.djangoproject.com/en/1.10/topics/http/urls/
|
|
|
Examples:
|
|
|
Function views
|
|
|
1. Add an import: from my_app import views
|
|
|
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
|
|
|
Class-based views
|
|
|
1. Add an import: from other_app.views import Home
|
|
|
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
|
|
|
Including another URLconf
|
|
|
1. Import the include() function: from django.conf.urls import url, include
|
|
|
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
|
|
"""
|
|
|
from django.conf import settings
|
|
|
from django.conf.urls.i18n import i18n_patterns
|
|
|
from django.conf.urls.static import static
|
|
|
from django.contrib.sitemaps.views import sitemap
|
|
|
from django.urls import path, include, re_path
|
|
|
from haystack.views import search_view_factory
|
|
|
|
|
|
from blog.views import EsSearchView
|
|
|
from djangoblog.admin_site import admin_site
|
|
|
from djangoblog.elasticsearch_backend import ElasticSearchModelSearchForm
|
|
|
from djangoblog.feeds import DjangoBlogFeed
|
|
|
from djangoblog.sitemap import (
|
|
|
ArticleSiteMap, CategorySiteMap, StaticViewSitemap, TagSiteMap, UserSiteMap
|
|
|
)
|
|
|
|
|
|
# 站点地图配置
|
|
|
sitemaps = {
|
|
|
'blog': ArticleSiteMap, # 文章
|
|
|
'Category': CategorySiteMap, # 分类
|
|
|
'Tag': TagSiteMap, # 标签
|
|
|
'User': UserSiteMap, # 用户
|
|
|
'static': StaticViewSitemap # 静态页面
|
|
|
}
|
|
|
|
|
|
# 自定义错误页面
|
|
|
handler404 = 'blog.views.page_not_found_view' # 404
|
|
|
handler500 = 'blog.views.server_error_view' # 500
|
|
|
handle403 = 'blog.views.permission_denied_view'# 403
|
|
|
|
|
|
urlpatterns = [
|
|
|
path('i18n/', include('django.conf.urls.i18n')), # 国际化
|
|
|
]
|
|
|
|
|
|
# 国际化URL(多语言支持)
|
|
|
urlpatterns += i18n_patterns(
|
|
|
re_path(r'^admin/', admin_site.urls), # 后台管理
|
|
|
re_path(r'', include('blog.urls', namespace='blog')), # 博客主体
|
|
|
re_path(r'mdeditor/', include('mdeditor.urls')), # Markdown编辑器
|
|
|
re_path(r'', include('comments.urls', namespace='comment')), # 评论
|
|
|
re_path(r'', include('accounts.urls', namespace='account')), # 账户
|
|
|
re_path(r'', include('oauth.urls', namespace='oauth')), # 第三方登录
|
|
|
re_path(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}), # 站点地图
|
|
|
re_path(r'^feed/$', DjangoBlogFeed()), # RSS订阅
|
|
|
re_path(r'^rss/$', DjangoBlogFeed()), # RSS订阅(备用)
|
|
|
# Elasticsearch搜索
|
|
|
re_path('^search', search_view_factory(
|
|
|
view_class=EsSearchView,
|
|
|
form_class=ElasticSearchModelSearchForm
|
|
|
), name='search'),
|
|
|
re_path(r'', include('servermanager.urls', namespace='servermanager')), # 服务器管理
|
|
|
re_path(r'', include('owntracks.urls', namespace='owntracks')), # 位置跟踪
|
|
|
prefix_default_language=False
|
|
|
)
|
|
|
|
|
|
# 静态文件URL
|
|
|
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
|
|
|
|
|
|
# 开发环境媒体文件URL
|
|
|
if settings.DEBUG:
|
|
|
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) |