示例#1
0
from django.urls.converters import register_converter
from .views import FindScheduleRedirectView, LessonCompleteView, LessonConfirmView, LessonDetailView, LessonListView, LessonCreateView, LessonDeleteView, LessonMarkAsPaidView, LessonSplit, LessonStartView, LessonUpdateView
from django.contrib.auth.decorators import login_required


class DateConverter:
    regex = '\d{2}-\d{2}-\d{4}'

    def to_python(self, value):
        return datetime.strptime(value, '%d-%m-%Y')

    def to_url(self, value):
        return value


register_converter(DateConverter, 'date')

app_name = 'lesson'
urlpatterns = [
    path('schedule/',
         login_required(LessonListView.as_view()),
         name='lesson-list'),
    path('schedule/<date:schedule_date>/',
         login_required(LessonListView.as_view()),
         name='lesson-list'),
    path('schedule/find/',
         login_required(FindScheduleRedirectView.as_view()),
         name='lesson-find-schedule'),
    path('create/',
         login_required(LessonCreateView.as_view()),
         name='lesson-create'),
示例#2
0
from django.urls.converters import register_converter


# 1.定义转换器
class MobileConverter:
    regex = '1[3-9]\d{9}'

    def to_python(self, value):
        return value

    # def to_url(self, value):
    #     return str(value)


# 2. 先注册转换器,才能在第三步使用
register_converter(MobileConverter, 'phone')

urlpatterns = [
    path('create/', creates),
    path('11000/11005/', shop),
    path('<int:cat_id>/<phone:mobile>/', goods),
    path('register/', register),
    path('json/', json),
    path('method/', method),
    path('res/', response),
    path('jsres/', jsonres),
    path('baidu/', baidu),
    path('set_cookie/', set_cookie),
    path('get_cookie/', get_cookie),
    path('set_session/', set_session),
    path('get_session/', get_session),
示例#3
0
#     regex='1[3-9]\d{9}'
#
#     def to_python(self,value):
#         return value
#
# converters.register_converter(MobileConverter,'mobile')
######################################
######################################
class MobileConverter:
    regex = '1[3-9]\d{9}'

    def to_python(self, value):
        return value


converters.register_converter(MobileConverter, 'mobile')
######################################

urlpatterns = [
    path('index/', index),
    # path('login/', login),
    # path('<cat_id>/<book_id>/',book),
    # path('login_json/', login_json),
    # path('header/', header),
    # path('detail/', detail),
    # path('jsonresponse/', jsonresponse),
    # path('to_index/', to_index),
    path('p/<int:tieba_id>/', views.baidu_tieba),
    path('register/<mobile:phone>/', views.tieba_register),
    path('tieba_login/', views.tieba_login),
    path('get_cookies/', views.get_cookies),
示例#4
0
文件: urls.py 项目: shmakovpn/pager
from django.urls import path, reverse_lazy
from django.conf import settings
from django.views.generic.base import RedirectView

from rest_framework.authtoken import views
from rest_framework_swagger.views import get_swagger_view

from django.urls.converters import register_converter
from .converters import *

# import views
from .views import *
# import api views
from .apiviews import *

register_converter(TilePathConverter, 'tile_path')
register_converter(DomainUserConverter, 'domain_user')

schema_view = get_swagger_view(title='Tiles Server API')
app_name = __package__

urlpatterns = [
    # index
    path('', IndexView.as_view(), name='index'),
    # login
    path('login/', LoginView.as_view(), name='login'),
    path('logout/', LogoutView.as_view(), name='logout'),
    # profile
    path('profile/<tile_path:tile_path><domain_user:username>.html',
         ProfileView.as_view(),
         name='profile'),
示例#5
0
    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'))
"""
# 导入 include 函数
from django.contrib import admin
from django.urls import path, include
# 以下代码注册自定义的路由转换器
from django.urls.converters import register_converter
from converters import MobileConverter
# 参数: 路由转换器,别名
register_converter(MobileConverter, "mobile")

urlpatterns = [
    # django默认就有的路由配置信息, 第一行不用管:
    path('admin/', admin.site.urls),

    # 添加如下的路由配置信息:
    # 设置子应用别名和子应用的子路由起别名 两种方法
    # path('', include(('子路由', '子应用名字'), namespace='总路由别名,可以随便命名')),
    # path(r'users/', include(('users.urls', "username"), namespace="username")),
    path(r'users/', include('users.urls')),
    path('', include('cookdemo.urls')),
    path('', include('classdemo.urls')),
    path('', include('booktest.urls')),
]
示例#6
0
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.http import Http404, HttpResponseForbidden
from django.urls import include, path
from django.urls.converters import register_converter
from django.views.defaults import page_not_found, permission_denied, server_error
from django.views.generic import RedirectView

from exporter import views as exporter_views

from . import converters, views

register_converter(converters.UnicodeSlugConverter, "uslug")
register_converter(converters.ItemIdConverter, "item_id")

tx_urlpatterns = (
    [
        path("", views.CampaignListView.as_view(), name="campaign-list"),
        path(
            "<uslug:slug>/", views.CampaignDetailView.as_view(), name="campaign-detail"
        ),
        path(
            "<uslug:campaign_slug>/export/csv/",
            exporter_views.ExportCampaignToCSV.as_view(),
            name="campaign-export-csv",
        ),
        path(
            "<uslug:campaign_slug>/export/bagit/",
            exporter_views.ExportCampaignToBagIt.as_view(),
            name="campaign-export-bagit",
示例#7
0
from django.urls import path
from django.conf import settings
from django.conf.urls.static import static
from django.views.generic.base import RedirectView
from rest_framework.authtoken import views
from rest_framework_swagger.views import get_swagger_view

from django.urls.converters import register_converter
from django.urls import reverse_lazy
from .converters import Md5Converter, DonloadTargetConverter

# importing views
from .views import *
from .apiviews import *

register_converter(Md5Converter, 'md5')
register_converter(DonloadTargetConverter, 'download_target')

schema_view = get_swagger_view(title='OCR Server API')
app_name = __package__
urlpatterns = [
    path('', RedirectView.as_view(url=reverse_lazy('admin:index'), permanent=False), name='root'),
    path('login/', views.obtain_auth_token, name='login'),
    path('upload/', UploadFile.as_view(), name='upload'),
    path('list/', OCRedFileList.as_view(), name='list'),
    path('remove/file/all/', RemoveFileAll.as_view(), name='remove_file_all'),
    path('remove/file/<md5:md5>/', RemoveFileMd5.as_view(), name='remove_file_md5'),
    path('remove/pdf/all/', RemovePdfAll.as_view(), name='remove_pdf_all'),
    path('remove/pdf/<md5:md5>/', RemovePdfMd5.as_view(), name='remove_pdf_md5'),
    path('create/pdf/all/', CreatePdfAll.as_view(), name='create_pdf_all'),
    path('create/pdf/<md5:md5>/', CreatePdfMd5.as_view(), name='create_pdf_md5'),
示例#8
0
from book.views import index, shop, register, json, method
from django.urls import converters
from django.urls.converters import register_converter


class MobileConverter:
    regex = '1[3-9]\d{9}'

    def to_python(self, value):
        return int(value)

    def to_url(self, value):
        return str(value)


register_converter(MobileConverter, 'thoop')

urlpatterns = [
    path('index/', index),
    path('<int:city_id>/<thoop:mobile>/', shop),
    path('register/', register),
    path('json/', json),
    path('method/', method),
]
'''class IntConverter:
    regex = '[0-9]+'

    def to_python(self, value):
        return int(value)

    def to_url(self, value):
示例#9
0
from django.urls.converters import register_converter

from .views import TestView


class CustomConverter:
    regex = '[6]{3}'

    def to_python(self, value):
        return int(value)

    def to_url(self, value):
        return str(value)


register_converter(CustomConverter, 'ctm')

urlpatterns = [
    re_path(r'^default/(?P<def>\w+)$', TestView.as_view(), name='default'),
    re_path(r'^default2/([\w]+)$', TestView.as_view(), name='default'),
    re_path(r'^special2/((?:first)|(?:third))$',
            TestView.as_view(),
            name='special'),
    path(
        '<ctm:one>/<ctm:two>/<ctm:three>/<ctm:four>/<ctm:five>/<ctm:six>/<ctm:seven>/<ctm:eight>',
        TestView.as_view(),
        name='complex'),
    re_path(r'^special1/(?P<choice>(:?first)|(:?second))$',
            TestView.as_view(),
            name='special'),
    re_path(