Python django.urls.include() Examples
The following are 19
code examples of django.urls.include().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.urls
, or try the search function
.
Example #1
Source File: document_fields_repository.py From lexpredict-contraxsuite with GNU Affero General Public License v3.0 | 6 votes |
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
Example #2
Source File: urls.py From openwisp-radius with GNU General Public License v3.0 | 6 votes |
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
Example #3
Source File: discovery.py From omniport-backend with GNU General Public License v3.0 | 6 votes |
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
Example #4
Source File: __init__.py From django-subadmin with MIT License | 6 votes |
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
Example #5
Source File: v1.py From lexpredict-contraxsuite with GNU Affero General Public License v3.0 | 5 votes |
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
Example #6
Source File: __init__.py From django-subadmin with MIT License | 5 votes |
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
Example #7
Source File: wagtail_hooks.py From wagtailcolourpicker with MIT License | 5 votes |
def register_admin_urls(): from wagtailcolourpicker import urls return [ path('wagtailcolourpicker/', include((urls, 'wagtailcolourpicker'))), ]
Example #8
Source File: urls.py From KubeOperator with Apache License 2.0 | 5 votes |
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
Example #9
Source File: wagtail_hooks.py From wagalytics with MIT License | 5 votes |
def register_admin_urls(): return [ re_path(r'^analytics/', include(urls)), ]
Example #10
Source File: sites.py From bioforum with MIT License | 4 votes |
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
Example #11
Source File: sites.py From weibo-analysis-system with MIT License | 4 votes |
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
Example #12
Source File: sites.py From myblog with GNU Affero General Public License v3.0 | 4 votes |
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
Example #13
Source File: sites.py From CTF_AWD_Platform with MIT License | 4 votes |
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
Example #14
Source File: sites.py From django_OA with GNU General Public License v3.0 | 4 votes |
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
Example #15
Source File: sites.py From Hands-On-Application-Development-with-PyCharm with MIT License | 4 votes |
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
Example #16
Source File: sites.py From Mxonline3 with Apache License 2.0 | 4 votes |
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
Example #17
Source File: django_app.py From scout_apm_python with MIT License | 4 votes |
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
Example #18
Source File: sites.py From online with GNU Affero General Public License v3.0 | 4 votes |
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
Example #19
Source File: sites.py From Dailyfresh-B2C with Apache License 2.0 | 4 votes |
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