The `urlpatterns` list routes URLs to views. For more information please see: https://docs.djangoproject.com/en/3.0/topics/http/urls/ Examples: Function views 1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.urls import path,include from django.conf.urls.static import static from django.conf import settings from blog.feeds import AllArticleRssFeed urlpatterns = [ path('admin/', admin.site.urls), path('',include('blog.urls', namespace='blog')), path('accounts/', include('allauth.urls')), path('accounts/', include('users.urls')), path('comment/', include('comment.urls', namespace='comment')),#comment path('feed/', AllArticleRssFeed(), name='rss'),#rss订阅 path('mdeditor/', include('mdeditor.urls')), ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)#加入这个才能显示media文件
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.urls import url from django.contrib import admin from django.conf.urls import include from rest_framework import routers from rest_framework_jwt.views import obtain_jwt_token from users.views import UserViewset from django.views.static import serve from webapp.settings import MEDIA_ROOT from blog.feeds import AllArticleRssFeed import xadmin router = routers.DefaultRouter() # 用户 router.register(r'register', UserViewset, base_name='users') urlpatterns = [ url(r'^admin/', xadmin.site.urls), url(r'', include('blog.urls', namespace='blog')), url(r'', include('users.urls', namespace='users')), url(r'', include('comments.urls', namespace='comments')), url(r'^api/', include(router.urls)), url(r'^media/(?P<path>.*)$', serve, {"document_root": MEDIA_ROOT}), url(r'^all/rss/$', AllArticleRssFeed(), name='rss'), ]
router = DefaultRouter() router.register(r'users', api_views.UserListSet) router.register(r'articles', api_views.ArticleListSet) router.register(r'tags', api_views.TagListSet) router.register(r'categorys', api_views.CategoryListSet) router.register(r'timelines', api_views.TimelineListSet) router.register(r'tools', api_views.ToolLinkListSet) # router.register(r'tools/categories', api_views.ToolCategoryListSet) # 网站地图 sitemaps = { 'articles': ArticleSitemap, 'tags': TagSitemap, 'categories': CategorySitemap } urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^accounts/', include('allauth.urls')), # allauth url(r'^accounts/', include('oauth.urls', namespace='oauth')), # oauth,只展现一个用户登录界面 url(r'^comment/', include('comment.urls', namespace='comment')), # comment url(r'^tool/', include('tool.urls', namespace='tool')), # tool url(r'', include('blog.urls', namespace='blog')), url(r'^feed/$', AllArticleRssFeed(), name='rss'), # rss订阅 url(r'sitemap.xml', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'), # 网站地图 url(r'^api/', include(router.urls, namespace='api')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # 加入这个才能显示media文件
RedirectView.as_view(url="/static/blog/img/favicon.ico")), path("adminx/", admin.site.urls), path("accounts/", include("allauth.urls")), # allauth path("accounts/", include( ("oauth.urls", "oauth"), namespace="oauth")), # oauth,只展现一个用户登录界面 path("", include(("blog.urls", "blog"), namespace="blog")), # blog path("comment/", include( ("comment.urls", "comment"), namespace="comment")), # comment path("robots.txt", robots, name="robots"), # robots path( "sitemap.xml", sitemap, {"sitemaps": sitemaps}, name="django.contrib.sitemaps.views.sitemap", ), # 网站地图 path("feed/", AllArticleRssFeed(), name="rss"), # rss订阅 path("api/v2/", include("apiv2.urls")), # API path("photos/", include("photo.urls")), # API ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # 加入这个才能显示media文件 if settings.API_FLAG: from api.urls import router urlpatterns.append( path("api/v1/", include((router.urls, router.root_view_name), namespace="api"))) # restframework if settings.TOOL_FLAG: urlpatterns.append(
from django.conf.urls import url, include from django.conf.urls.static import static from django.conf import settings from django.contrib import admin from blog.feeds import AllArticleRssFeed from django.contrib.sitemaps.views import sitemap from blog.sitemaps import ArticleSitemap, CategorySitemap, TagSitemap # 网站地图 sitemaps = { 'articles': ArticleSitemap, 'tags': TagSitemap, 'categories': CategorySitemap } urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^accounts/', include('allauth.urls')), # allauth url(r'accounts/', include('oauth.urls', namespace='oauth')), # oauth,只展现一个用户登录界面 url('', include('blog.urls', namespace='blog')), # blog url(r'^comments/', include('comment.urls', namespace='comment')), # comment url(r'^blog/rss/$', AllArticleRssFeed(), name='rss'), url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}, name='django.contrib.sitemaps.views.sitemap'), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # 加入这个才能显示media文件
from django.shortcuts import render from django.urls import path from blog.views import IndexView, CategoryView, CategoryNameView, ArchivesView, AboutView, SearchView, ArticleView from blog.feeds import AllArticleRssFeed urlpatterns = [ path('admin/', admin.site.urls), path('', IndexView.as_view(), name='index'), path('category', CategoryView.as_view(), name='category'), path('category/(?P<category_name>.*)', CategoryNameView.as_view(), name='category_name'), path('archives', ArchivesView.as_view(), name='archives'), path('about', AboutView.as_view(), name='about'), path('search', SearchView.as_view(), name='search'), path('article/<int:id>/', ArticleView.as_view(), name='article'), path('feed', AllArticleRssFeed(), name='feed'), ] if settings.DEBUG: urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) def page_not_found(request, exception): """ 404 :param request: :return: """ return render(request, '../templates/404.html', {}, status=404) def server_error(request):