本文整理汇总了Python中django.urls.include方法的典型用法代码示例。如果您正苦于以下问题:Python urls.include方法的具体用法?Python urls.include怎么用?Python urls.include使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.urls
的用法示例。
在下文中一共展示了urls.include方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def get_urls(self):
def wrap(view):
def wrapper(*args, **kwargs):
return self.admin_site.admin_view(view)(*args, **kwargs)
return update_wrapper(wrapper, view)
base_viewname = self.get_base_viewname()
urlpatterns = [
path('' , include(self.get_subadmin_urls())),
path('', wrap(self.changelist_view), name='%s_changelist' % base_viewname),
path('add/', wrap(self.add_view), name='%s_add' % base_viewname),
re_path(r'^(.+)/history/$', wrap(self.history_view), name='%s_history' % base_viewname),
re_path(r'^(.+)/delete/$', wrap(self.delete_view), name='%s_delete' % base_viewname),
re_path(r'^(.+)/change/$', wrap(self.change_view), name='%s_change' % base_viewname),
]
urlpatterns = urlpatterns
return urlpatterns
示例2: _init_document_fields
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def _init_document_fields():
custom_apps = [i.replace('apps.', '') for i in settings.INSTALLED_APPS if i.startswith('apps.')]
for app_name in custom_apps:
module_str = 'apps.%s.document_fields' % app_name
spec = importlib.util.find_spec(module_str)
if not spec:
continue
include_fields = include((module_str, app_name)) # namespace=app_name)
try:
app_document_fields = include_fields[0].__getattribute__('DOCUMENT_FIELDS')
except AttributeError:
continue
for field_config in app_document_fields:
doc_class = field_config.document_class
doc_class_name = '{0}.{1}'.format(app_name, doc_class.__name__)
field = field_config.field
doc_class_fields = DOCUMENT_FIELDS.get(doc_class_name)
if not doc_class_fields:
doc_class_fields = {}
DOCUMENT_FIELDS[doc_class_name] = doc_class_fields
doc_class_fields[field] = field_config
示例3: _prepare_http_urlpatterns
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def _prepare_http_urlpatterns(app_set):
"""
Generate HTTP URL patterns for the given list of tuples of apps and
configuration objects
:param app_set: the given list of tuples of apps and their configuration
objects
:return: the HTTP URL patterns
"""
http_urlpatterns = list()
for (app, app_configuration) in app_set:
if app_configuration.is_allowed:
url = app_configuration.base_urls.http
if url is not None:
if app_configuration.is_api:
url = f'api/{url}'
http_urlpatterns.append(
path(url, include(f'{app}.http_urls'))
)
return http_urlpatterns
示例4: get_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def get_urls(api_views=None, social_views=None):
"""
Returns a list of urlpatterns
Arguements:
api_views(optional): views for Radius API
social_view(optional): views for social login (if enabled)
"""
if not social_views:
from .social import views as social_views
urls = [path('api/v1/', include(get_api_urls(api_views)))]
if app_settings.SOCIAL_LOGIN_ENABLED:
urls.append(
path(
'freeradius/social-login/<slug:slug>/',
social_views.redirect_cp,
name='redirect_cp',
)
)
return urls
示例5: get_subadmin_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def get_subadmin_urls(self):
urlpatterns = []
for modeladmin in self.subadmin_instances:
regex = r'^(.+)/%s/' % modeladmin.model._meta.model_name
urls = [
re_path(regex , include(modeladmin.urls))
]
urlpatterns += urls
return urlpatterns
示例6: get_api_v1_urlpatterns
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def get_api_v1_urlpatterns():
_urlpatterns = [
path('', include('users.urls')),
path('', include('celery_api.urls.api_urls')),
path('', include('kubeops_api.api_url')),
path('', include('cloud_provider.api_url')),
path('', include('storage.api_url')),
path('', include('log.api_url')),
path('', include('message_center.api_url')),
path('', include("ops.api_url"))
]
return _urlpatterns
示例7: has_object_permission
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def has_object_permission(self, request, view, obj):
# Warn! self.get_object() initializes this check! so include it in custom view func!
if request.user.is_reviewer:
return obj.reviewers.filter(pk=request.user.pk).exists()
return True
示例8: register_admin_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def register_admin_urls():
from wagtailcolourpicker import urls
return [
path('wagtailcolourpicker/', include((urls, 'wagtailcolourpicker'))),
]
示例9: register_admin_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def register_admin_urls():
return [
re_path(r'^analytics/', include(urls)),
]
示例10: get_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def get_urls(self):
from django.urls import include, path, re_path
# Since this module gets imported in the application's root package,
# it cannot import models from other applications at the module level,
# and django.contrib.contenttypes.views imports ContentType.
from django.contrib.contenttypes import views as contenttype_views
def wrap(view, cacheable=False):
def wrapper(*args, **kwargs):
return self.admin_view(view, cacheable)(*args, **kwargs)
wrapper.admin_site = self
return update_wrapper(wrapper, view)
# Admin-site-wide views.
urlpatterns = [
path('', wrap(self.index), name='index'),
path('login/', self.login, name='login'),
path('logout/', wrap(self.logout), name='logout'),
path('password_change/', wrap(self.password_change, cacheable=True), name='password_change'),
path(
'password_change/done/',
wrap(self.password_change_done, cacheable=True),
name='password_change_done',
),
path('jsi18n/', wrap(self.i18n_javascript, cacheable=True), name='jsi18n'),
path(
'r/<int:content_type_id>/<path:object_id>/',
wrap(contenttype_views.shortcut),
name='view_on_site',
),
]
# Add in each model's views, and create a list of valid URLS for the
# app_index
valid_app_labels = []
for model, model_admin in self._registry.items():
urlpatterns += [
path('%s/%s/' % (model._meta.app_label, model._meta.model_name), include(model_admin.urls)),
]
if model._meta.app_label not in valid_app_labels:
valid_app_labels.append(model._meta.app_label)
# If there were ModelAdmins registered, we should have a list of app
# labels for which we need to allow access to the app_index view,
if valid_app_labels:
regex = r'^(?P<app_label>' + '|'.join(valid_app_labels) + ')/$'
urlpatterns += [
re_path(regex, wrap(self.app_index), name='app_list'),
]
return urlpatterns
示例11: get_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def get_urls(self):
from django.urls import include, path, re_path
from xadmin.views.base import BaseAdminView
if settings.DEBUG:
self.check_dependencies()
def wrap(view, cacheable=False):
def wrapper(*args, **kwargs):
return self.admin_view(view, cacheable)(*args, **kwargs)
wrapper.admin_site = self
return update_wrapper(wrapper, view)
# Admin-site-wide views.
urlpatterns = [
path('jsi18n/', wrap(self.i18n_javascript, cacheable=True), name='jsi18n')
]
# Registed admin views
# inspect[isclass]: Only checks if the object is a class. With it lets you create an custom view that
# inherits from multiple views and have more of a metaclass.
urlpatterns += [
re_path(
_path,
wrap(self.create_admin_view(clz_or_func))
if inspect.isclass(clz_or_func) and issubclass(clz_or_func, BaseAdminView)
else include(clz_or_func(self)),
name=name
)
for _path, clz_or_func, name in self._registry_views
]
# Add in each model's views.
for model, admin_class in iteritems(self._registry):
view_urls = [
re_path(
_path,
wrap(self.create_model_admin_view(clz, model, admin_class)),
name=name % (model._meta.app_label, model._meta.model_name)
)
for _path, clz, name in self._registry_modelviews
]
urlpatterns += [
re_path(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name), include(view_urls))
]
return urlpatterns
示例12: get_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def get_urls(self):
from django.urls import include, path, re_path
from xadmin.views.base import BaseAdminView
if settings.DEBUG:
self.check_dependencies()
def wrap(view, cacheable=False):
def wrapper(*args, **kwargs):
return self.admin_view(view, cacheable)(*args, **kwargs)
wrapper.admin_site = self
return update_wrapper(wrapper, view)
# Admin-site-wide views.
urlpatterns = [
path('jsi18n/', wrap(self.i18n_javascript, cacheable=True), name='jsi18n')
]
# Registed admin views
# inspect[isclass]: Only checks if the object is a class. With it lets you create an custom view that
# inherits from multiple views and have more of a metaclass.
urlpatterns += [
re_path(
_path,
wrap(self.create_admin_view(clz_or_func))
if inspect.isclass(clz_or_func) and issubclass(clz_or_func, BaseAdminView)
else include(clz_or_func(self)),
name=name
)
for _path, clz_or_func, name in self._registry_views
]
# Add in each model's views.
for model, admin_class in iteritems(self._registry):
view_urls = [
re_path(
_path,
wrap(self.create_model_admin_view(clz, model, admin_class)),
name=name % (model._meta.app_label, model._meta.model_name)
)
for _path, clz, name in self._registry_modelviews
]
urlpatterns += [
re_path(r'^%s/%s/' % (model._meta.app_label, model._meta.model_name), include(view_urls))
]
return urlpatterns
示例13: urlpatterns
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import include [as 别名]
def urlpatterns():
"""
URL's as a lazy object because they touch admin.site.urls and that isn't
ready until django.setup() has been called
"""
if django.VERSION >= (2, 0):
from django.urls import include, path
patterns = [
path("", home),
path("hello/", hello),
path("crash/", crash),
path("return-error/", return_error),
path("cbv/", CbvView.as_view()),
path("sql/", sql),
path("sql-kwargs/", sql_kwargs),
path("sql-type-errors/", sql_type_errors),
path("template/", template),
path("template-response/", template_response),
path("admin/", admin.site.urls),
path("drf-router/", include(drf_router.urls)),
]
if tastypie_api:
patterns.append(path("tastypie-api/", include(tastypie_api.urls)))
return patterns
else:
from django.conf.urls import include, url
patterns = [
url(r"^$", home),
url(r"^hello/$", hello),
url(r"^crash/$", crash),
url(r"^return-error/$", return_error),
url(r"^cbv/$", CbvView.as_view()),
url(r"^sql/$", sql),
url(r"^sql-kwargs/$", sql_kwargs),
url(r"^sql-type-errors/$", sql_type_errors),
url(r"^template/$", template),
url(r"^template-response/$", template_response),
url(r"^admin/", admin.site.urls),
url(r"^drf-router/", include(drf_router.urls)),
]
if tastypie_api:
patterns.append(url(r"^tastypie-api/", include(tastypie_api.urls)))
return patterns