Exemple #1
0
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.contrib.auth.views import LoginView
from django.urls import path, include
from book.views import BooksView, BookView
from registration.views import CustomPasswordChangeView
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    path('admin/', admin.site.urls),
    path('register/', include('registration.urls')),
    path('login/', LoginView.as_view(template_name='login.html')),
    path('', LoginView.as_view(template_name='main.html')),
    path('', include('django.contrib.auth.urls')),
    path('books', BooksView.as_view()),
    path('books/p<page>', BooksView.as_view()),
    path('book/<id>', BookView.as_view()),
    path('user/<id>', CustomPasswordChangeView.as_view()),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Exemple #2
0
app_name = 'book'

urlpatterns = [
    # name 就是给url起一个名字
    # 我们可以通过name找到这个路由
    re_path(r'^home/$', index, name='index'),

    # http://127.0.0.1:8000/分类id/书籍id/
    # http://127.0.0.1:8000/category_id/book_id/
    # 分组来获取正则中的数据
    # 根据位置来获取 url中的参数
    # url(r'^(\d+)/(\d+)/$',detail),

    # 关键字参数--推荐大家使用关键字参数
    re_path(r'^(?P<category_id>\d+)/(?P<book_id>\d+)/$', detail),

    # cookie的第一次请求
    re_path(r'^set_cookie/$', set_cookie),

    # cookie的第二次及其之后的请求
    re_path(r'^get_cookie/$', get_cookie),
    re_path(r'^set_session/$', set_session),
    re_path(r'^get_session/$', get_session),

    # url的第一个参数是 正则
    # url的第二个参数是 视图函数名
    re_path(r'^login/$', BookView.as_view()),
    re_path(r'^center/$', CenterView.as_view()),
    re_path(r'^index/$', HomeView.as_view()),
]
Exemple #3
0
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
from django.conf.urls import url

from book.views import (
    BookView, BookItemView, CommentListView, CommentItemView, CommentChildrenView, BuyView,
    SearchHistoryView, SearchHottestView,
)


urlpatterns = [
    url(r'^/book$', BookView.as_view(), name='book'),
    url(r'^/book/(?P<book_id>[0-9]+)$', BookItemView.as_view(), name='book_item'),
    url(r'^/book/(?P<book_id>[0-9]+)/comment$', CommentListView.as_view(), name='comment_list'),
    url(r'^/book/(?P<book_id>[0-9]+)/buy$', BuyView.as_view(), name='buy'),
    url(r'^/comment/(?P<comment_id>[0-9]+)$', CommentItemView.as_view(), name='comment_item'),
    url(r'^/comment/(?P<comment_id>[0-9]+)/children$', CommentChildrenView.as_view(), name='comment_children'),
    url(r'^/search/hottest$', SearchHottestView.as_view(), name='search_hotest'),
    url(r'^/search/history$', SearchHistoryView.as_view(), name='search_history'),
]
Exemple #4
0
    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.contrib import admin
from django.conf.urls import url, include
from django.views.decorators.cache import cache_page

from rest_framework import routers
from rest_framework.documentation import include_docs_urls

from book.api import StoryViewSet
from .custom_site import custom_site
from book.views import IndexView, CategoryView, BookView

router = routers.DefaultRouter()
router.register(r'story', StoryViewSet)

urlpatterns = [
    url('^$', IndexView.as_view(), name='index'),
    url('^category/(?P<category_id>\d+).html$',
        cache_page(60 * 10)(CategoryView.as_view()),
        name='category'),
    url('book/(?P<pk>\d+).html$', BookView.as_view(), name='detail'),
    url(r'^admin/', admin.site.urls),
    url(r'^cus_admin/', custom_site.urls),
    url(r'api/', include(router.urls)),
    url(r'^api/docs/', include_docs_urls(title='My Book API')),
]
Exemple #5
0
"""project URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.2/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
from home.views import HomeView
from book.views import BookView, AddBook, BookDetail, BookUpdate, BookDelete

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', HomeView.as_view(), name='home'),
    path('booklist/', BookView.as_view(), name='booklist'),
    path('addbook/', AddBook.as_view(), name='addbook'),
    path('bookdetail/<int:pk>', BookDetail.as_view(), name='bookdetail'),
    path('bookupdate/<int:pk>', BookUpdate.as_view(), name='bookupdate'),
    path('book/delete/<int:pk>', BookDelete.as_view(), name='bookdelete'),
]
Exemple #6
0
from django.urls import path

from book.views import BookView, list_book

app_name = "book"

urlpatterns = [
    path("<int:book_id>", BookView.as_view(), name="get"),
    path("list", list_book, name="list"),
]
Exemple #7
0
urlpatterns = [
    url(r'^v1/publishers/$',
        PublisherView.as_view({
            "get": "list",
            "post": "create"
        })),
    url(
        r'^v1/publishers/(?P<pk>\d+)/$',
        PublisherView.as_view({
            "get": 'retrieve',
            "put": "update",
            "delete": "destroy"
        })),
    url(r'^v1/books/$', BookView.as_view({
        "get": "list",
        "post": "create"
    })),
    url(
        r'^v1/books/(?P<pk>\d+)/$',
        BookView.as_view({
            "get": 'retrieve',
            "put": "update",
            "delete": "destroy"
        })),
    url(r'^v1/authors/$', AuthorView.as_view({
        "get": "list",
        "post": "create"
    })),
    url(
        r'^v1/authors/(?P<pk>\d+)/$',
        AuthorView.as_view({
Exemple #8
0
from django.views.generic import RedirectView
from django.urls.conf import include, include
from django.contrib import admin
from django.urls import path

from book.views import BookView

urlpatterns = [

    # Admin
    path('admin/', admin.site.urls),

    # Accounts
    path('accounts/', include('django.contrib.auth.urls')),
    path('accounts/', include('accounts.urls')),

    # Book
    path('', BookView.as_view(), name='home'),
    path('book/', include('book.urls')),
]
Exemple #9
0
from django.contrib import admin
from django.urls import path

from book.views import BookView, BookDeleteView, BookDetailView, BookListView, BookCreateView, BookUpdateView

urlpatterns = [

    # Admin
    path('admin/', admin.site.urls),

    # Book Views
    path('', BookView.as_view()),
    path('book/', BookListView.as_view(), name='book_list'),
    path('book/<int:pk>', BookDetailView.as_view(), name='book_detail'),
    path('book/add', BookCreateView.as_view(), name='book_add'),
    path('book/<int:pk>/', BookUpdateView.as_view(), name='book_edit'),
    path('book/<int:pk>/delete', BookDeleteView.as_view(), name='book_delete'),
]
from django.urls import path

from book.views import BookView

urlpatterns = [
    # Container commands
    path('books/', BookView.as_view()),

]
Exemple #11
0
# coding: utf-8
from django.conf.urls import url
from book.views import random_book, GenreListView, WikiListView, GenreView, BookListView, BookView


urlpatterns = [
    url(r'^$', GenreListView.as_view()),

    url(r'^genre/$', GenreListView.as_view(), name='book_genres'),
    url(r'^orphans/$', GenreView.as_view(), name='book_genres_orphans'),

    url(r'^genre/(?P<slug>[\w-]+)/$', GenreView.as_view(), name='book_genre'),

    url(r'^genre/__page.opt$', WikiListView.as_view(), name='book_genres_wiki'),
    url(r'^genre/(?P<slug>[\w-]+)/__page.opt$', WikiListView.as_view(), name='book_genre_wiki'),

    url(r'^random/(?P<genre>[\w-]+)?/?$', random_book, name='random_book'),
    url(r'^book/$', BookListView.as_view(), name='books'),
    url(r'^book/(?P<slug>[\w-]+)/$', BookView.as_view(), name='book'),

]
Exemple #12
0
from django.urls import path, include

from book.views import (
    BookView,
    CommentCreateView,
    BookFileUploadView,
    CommentApiView,
    CommentEditView,
    CommentDeleteView,
    BookDownloadView,
    BookDetailView, GenreView, AuthorView,
)

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/v1/books/', BookView.as_view()),
    path('api/v1/genres/', GenreView.as_view()),
    path('api/v1/authors/', AuthorView.as_view()),
    path('api/v1/book/<int:pk>', BookDetailView.as_view()),
    path('api/v1/comments/', CommentApiView.as_view()),
    path('api/v1/comments/create/', CommentCreateView.as_view()),
    path('api/v1/comments/update/<int:pk>', CommentEditView.as_view()),
    path('api/v1/comments/<int:pk>', CommentDeleteView.as_view()),
    path('api/v1/file/upload', BookFileUploadView.as_view()),
    path('auth/', include('djoser.urls')),
    path('auth/', include('djoser.urls.authtoken')),
    path('auth/', include('djoser.urls.jwt')),
    path('api/download/<int:pk>', BookDownloadView.as_view()),
]

if settings.DEBUG: