Пример #1
0
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
import xadmin
from django.contrib import admin
from django.urls import path
from django.conf.urls import url, include
from django.conf import settings
from django.conf.urls.static import static
from blog.views import IndexView, CategoryView, TagView, PostDetailView, SearchView, AuthorView
from config.views import LinkListView
from comment.views import CommentView
from .custom_site import custom_site
from .autocomplete import CategoryAutoComplete, TagAutoComplete
urlpatterns = [
    url(r'^$', IndexView.as_view(), name='index'),
    url(r'^search/$', SearchView.as_view(), name='search'),
    url(r'^category/(?P<category_id>\d+)/$', CategoryView.as_view(), name='category-list'),
    url(r'^tag/(?P<tag_id>\d+)/$', TagView.as_view(), name='tag-list'),
    url(r'^post/(?P<post_id>\d+).html$', PostDetailView.as_view(), name='post-detail'),
    url(r'^author/(?P<owner_id>\d+).html$', AuthorView.as_view(), name='author'),
    url(r'^links/$', LinkListView.as_view(), name='links'),
    url(r'^comment/$', CommentView.as_view(), name='comment'),
    url(r'^super_admin/', admin.site.urls, name='super-admin'),
    # url(r'^admin/', custom_site.urls, name='admin'),
    url(r'^admin/', xadmin.site.urls, name='xadmin'),
    url(r'^category-autocomplete/$', CategoryAutoComplete.as_view(), name='category-autocomplete'),
    url(r'^tag-autocomplete/$', TagAutoComplete.as_view(), name='tag-autocomplete'),
    url(r'^ckeditor/', include('ckeditor_uploader.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Пример #2
0
app_name = 'blog'

urlpatterns = [
    # path('', post_list, name='index'),
    path('', IndexView.as_view(), name='index'),
    path('category/<int:category_id>/',
         CategoryView.as_view(),
         name='category-list'),
    path('tag/<int:tag_id>/', TagView.as_view(), name='tag-list'),
    # path('post/<int:post_id>.html', post_detail, name='post-detail'),
    path('post/<int:post_id>.html',
         PostDetailView.as_view(),
         name='post-detail'),
    path('search/', SearchView.as_view(), name='search'),
    path('author/<int:owner_id>/', AuthorView.as_view(), name='author'),
    path('links/', LinkListView.as_view(), name='links'),
    path('comment/', CommentView.as_view(), name='comment'),
    path('super_admin/', admin.site.urls, name='super-admin'),
    path('admin/', custom_site.urls, name='admin'),
    path('xadmin/', xadmin.site.urls, name='admin'),
    path('ckeditor/', include('ckeditor_uploader.urls')),
    path('category-autocomplete/',
         CategoryAutocomplete.as_view(),
         name='category-autocomplete'),
    path('tag-autocomplete/',
         TagsAutocomplete.as_view(),
         name='tag-autocomplete'),
    # path('api/post/', post_list, name='post-list'),
    # path('api/post/', PostList.as_view(), name='post-list'),
    path('api/', include((router.urls, 'blog'), namespace="api")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Пример #3
0
from blog.apis import PostViewSet, CategoryViewSet, LatestPostViewSet, TagViewSet

from rest_framework.documentation import include_docs_urls

router = routers.DefaultRouter()
router.register(r'post', PostViewSet, base_name='api-post') # 文章列表、详情
router.register(r'latestpost', LatestPostViewSet, base_name='api-latestpost') # 最新文章列表、详情
router.register(r'category', CategoryViewSet, base_name='api-category') # 分类列表
router.register(r'tag', TagViewSet, base_name='api-tag')

urlpatterns = [
    path('', IndexView.as_view(), name='index'),
    re_path(r'^category/(?P<category_id>\d+)/$', CategoryView.as_view(), name='category-list'),
    re_path(r'^tag/(?P<tag_id>\d+)/$', TagView.as_view(), name='tag-list'),
    re_path(r'^post/(?P<post_id>\d+).html$', PostDetailView.as_view(), name='post-detail'),
    re_path(r'links/$', LinkListView.as_view(), name='links'),
    re_path(r'search/$', SearchView.as_view(), name='search'),
    re_path(r'^author/(?P<owner_id>\d+)/$', AuthorView.as_view(), name='author'),
    re_path(r'^comment/$', CommentView.as_view(), name='comment'),
    path('super_admin/', admin.site.urls, name='super-admin'),
    path('admin/', xadmin.site.urls, name='xadmin'),

    # Rss/Map
    re_path('rss|feed/$', LatestPostFeed(), name='rss'),
    re_path('sitemap\.xml$', sitemap_views.sitemap, {'sitemaps': {'posts': PostSitemap}}),

    # 解决外键加载问题
    path('category-autocomplete/', CategoryAutocomplete.as_view(), name='category-autocomplete'),
    path('tag-autocomplete/', TagAutocomplete.as_view(), name='tag-autocomplete'),

    # 图片上传
Пример #4
0
from blog.apis import post_list, PostList

import xadmin

from .autocomplete import CategoryAutocomplete, TagAutocomplete

urlpatterns = [
    url(r'^$', IndexView.as_view(), name="index"),
    url(r'^category/(?P<category_id>\d+)/$',
        CategoryView.as_view(),
        name="category-list"),
    url(r'^tag/(?P<tag_id>\d+)/$', TagView.as_view(), name="tag-list"),
    url(r'^post/(?P<post_id>\d+).html/$',
        PostDetailView.as_view(),
        name="post-detail"),
    url(r'^links/$', LinkListView.as_view(), name="links"),
    url(r'^search/$', SearchView.as_view(), name='search'),
    url(r'^author/(?P<owner_id>\d+)/$', AuthorView.as_view(), name='author'),
    url(r'^comment/$', CommentView.as_view(), name='comment'),
    url(r'^rss|feed', LatestPostFeed(), name='rss'),
    url(r'^sitemap\.xml$', sitemap_views.sitemap,
        {'sitemaps': {
            'posts': PostSitemap
        }}),
    url(r'^admin/', xadmin.site.urls, name='xadmin'),
    url(r'^category-autocomplete/$',
        CategoryAutocomplete.as_view(),
        name='category-autocomplete'),
    url(r'^tag-autocomplete/$',
        TagAutocomplete.as_view(),
        name='tag-autocomplete'),
Пример #5
0
routers = DefaultRouter()
routers.register('post', PostViewSet, basename='api-post')
routers.register('category', CategoryViewSet, basename='api-category')
routers.register('tag', TagViewSet, basename='api-tag')

urlpatterns = [
    path('', IndexView.as_view(), name="index"),
    path('myposts/', MyPostsView.as_view(), name="my_posts"),
    path('post/<int:post_id>.html',
         PostDetailView.as_view(),
         name="post_detail"),
    path('category/<int:category_id>',
         CategoryView.as_view(),
         name="category_list"),
    path('tag/<int:tag_id>', TagView.as_view(), name="tag_list"),
    path('links/', LinkListView.as_view(), name="links"),
    path('search/<int:type_id>', SearchView.as_view(), name='search'),
    path('author/<int:author_id>', AuthorView.as_view(), name='author'),
    path('comment/', CommentView.as_view(), name='comment'),
    path('ckeditor/', include('ckeditor_uploader.urls')),
    path('rss/', LatestPostFeed(), name='rss'),
    path('sitemap.xml/',
         sitemap_views.sitemap, {'sitemaps': {
             'posts': PostSitemap
         }},
         name='sitemap'),
    path('super_admin/', admin.site.urls, name="super_admin"),
    path('admin/', custom_site.urls, name="admin"),
    path('api/', include((routers.urls, 'blog'), namespace='api')),
    path('api/docs/', include_docs_urls(title='API document')),
]