本文整理汇总了Python中django.urls.path方法的典型用法代码示例。如果您正苦于以下问题:Python urls.path方法的具体用法?Python urls.path怎么用?Python urls.path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.urls
的用法示例。
在下文中一共展示了urls.path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def get_urls(self):
from django.urls import path
def wrap(view):
def wrapper(*args, **kwargs):
return self.admin_site.admin_view(view)(*args, **kwargs)
wrapper.model_admin = self
return update_wrapper(wrapper, view)
info = self.model._meta.app_label, self.model._meta.model_name
urlpatterns = [
path('', wrap(self.changelist_view), name='%s_%s_changelist' % info),
path('add/', wrap(self.add_view), name='%s_%s_add' % info),
path('autocomplete/', wrap(self.autocomplete_view), name='%s_%s_autocomplete' % info),
path('<path:object_id>/history/', wrap(self.history_view), name='%s_%s_history' % info),
path('<path:object_id>/delete/', wrap(self.delete_view), name='%s_%s_delete' % info),
path('<path:object_id>/change/', wrap(self.change_view), name='%s_%s_change' % info),
# For backwards compatibility (was the change url before 1.9)
path('<path:object_id>/', wrap(RedirectView.as_view(
pattern_name='%s:%s_%s_change' % ((self.admin_site.name,) + info)
))),
]
return urlpatterns
示例2: __init__
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def __init__(self, name='xadmin'):
self.name = name
self.app_name = 'xadmin'
self._registry = {} # model_class class -> admin_class class
self._registry_avs = {} # admin_view_class class -> admin_class class
self._registry_settings = {} # settings name -> admin_class class
self._registry_views = []
# url instance contains (path, admin_view class, name)
self._registry_modelviews = []
# url instance contains (path, admin_view class, name)
self._registry_plugins = {} # view_class class -> plugin_class class
self._admin_view_cache = {}
# self.check_dependencies()
self.model_admins_order = 0
示例3: urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def urls(self):
def key_func(r):
f, url, methods, params, returns = r
return url
urls_map = {}
routes = sorted(self._routes, key=key_func)
groups = itertools.groupby(routes, key=key_func)
for url, group in groups:
view = self._make_view(list(group))
urls_map[url] = path(url, view)
# keep urls same order with self._routes
# and constant url should priority then path argument
urls = []
urls_priority = []
urls_added = set()
for f, url, methods, params, returns in self._routes:
if url not in urls_added:
urls_added.add(url)
if '<' in url and ':' in url and '>' in url:
urls.append(urls_map[url])
else:
urls_priority.append(urls_map[url])
return urls_priority + urls
示例4: test_no_resolver
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def test_no_resolver(self, request_factory):
request = request_factory.get('/admin/')
openapi_request = DjangoOpenAPIRequest(request)
path = {}
query = {}
headers = {
'Cookie': '',
}
cookies = {}
assert openapi_request.parameters == RequestParameters(
path=path,
query=query,
header=headers,
cookie=cookies,
)
assert openapi_request.method == request.method.lower()
assert openapi_request.full_url_pattern == \
request._current_scheme_host + request.path
assert openapi_request.body == request.body
assert openapi_request.mimetype == request.content_type
示例5: test_simple
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def test_simple(self, request_factory):
from django.urls import resolve
request = request_factory.get('/admin/')
request.resolver_match = resolve('/admin/')
openapi_request = DjangoOpenAPIRequest(request)
path = {}
query = {}
headers = {
'Cookie': '',
}
cookies = {}
assert openapi_request.parameters == RequestParameters(
path=path,
query=query,
header=headers,
cookie=cookies,
)
assert openapi_request.method == request.method.lower()
assert openapi_request.full_url_pattern == \
request._current_scheme_host + request.path
assert openapi_request.body == request.body
assert openapi_request.mimetype == request.content_type
示例6: get_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def get_urls(self):
urls = super().get_urls()
action_row_urls = []
for method_name in self.actions_row:
method = getattr(self, method_name)
action_row_urls.append(
path(getattr(method, 'url_path', method_name) + '/<path:pk>/', self.admin_site.admin_view(method), name=method_name))
action_detail_urls = []
for method_name in self.actions_detail:
method = getattr(self, method_name)
action_detail_urls.append(
path(getattr(method, 'url_path', method_name) + '/<path:pk>/', self.admin_site.admin_view(method), name=method_name))
action_list_urls = []
for method_name in self.actions_list:
method = getattr(self, method_name)
action_list_urls.append(
path(getattr(method, 'url_path', method_name), self.admin_site.admin_view(method), name=method_name)
)
return action_list_urls + action_row_urls + action_detail_urls + urls
示例7: change_view
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def change_view(self, request, object_id, form_url='', extra_context=None):
if extra_context is None:
extra_context = {}
actions = []
for method_name in self.actions_detail:
method = getattr(self, method_name)
actions.append({
'title': getattr(method, 'short_description', method_name),
'path': reverse('admin:' + method_name, args=(object_id, ))
})
extra_context.update({
'actions_list': actions,
})
return super(ActionsModelAdmin, self).change_view(request, object_id, form_url, extra_context)
示例8: changelist_view
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def changelist_view(self, request, extra_context=None):
if extra_context is None:
extra_context = {}
actions = []
for method_name in self.actions_list:
method = getattr(self, method_name)
actions.append({
'title': getattr(method, 'short_description', method_name),
'path': reverse('admin:' + method_name)
})
extra_context.update({
'actions_list': actions,
})
return super(ActionsModelAdmin, self).changelist_view(request, extra_context)
示例9: predict
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def predict(image_path,datasetid):
logger.info("predicting "+image_path+" "+str(datasetid))
dataset=DataSet.objects.get(pk=datasetid)
modelpath=dataset.model.path
logger.info("model path "+modelpath)
model=load_model(modelpath)
labels=json.loads(dataset.model_labels)
img = Image.open(image_path)
img = img.convert('L')
img = img.resize((256, 256), Image.ANTIALIAS)
result= model.predict(np.array(img).reshape(-1,256,256, 1))
max=result[0]
idx=0
for i in range(1,len(result)):
if max<result[i]:
max=result[i]
idx=i
logger.info(result[idx])
logger.info(labels[idx])
return labels[idx]
示例10: _prepare_app_configuration_list
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def _prepare_app_configuration_list(directory):
"""
Produce a list of tuples of apps and their configurations after scanning
the specified directory
:param directory: the directory to scan for apps
:return: the list of tuples of apps and their configuration objects
"""
sub_directories = [
sub_directory
for sub_directory in os.listdir(path=directory)
if os.path.isdir(os.path.join(directory, sub_directory))
]
apps_and_configs = list()
for sub_directory in sub_directories:
config_path = os.path.join(directory, sub_directory, 'config.yml')
if os.path.isfile(config_path):
with open(config_path) as config_file:
config_dictionary = yaml.safe_load(config_file)
config_object = AppConfiguration(dictionary=config_dictionary)
apps_and_configs.append(
(sub_directory, config_object,)
)
return apps_and_configs
示例11: _prepare_http_urlpatterns
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [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
示例12: _prepare_ws_urlpatterns
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def _prepare_ws_urlpatterns(app_set):
"""
Generate WS 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 WS URL patterns
"""
ws_urlpatterns = list()
for (app, app_configuration) in app_set:
if app_configuration.is_allowed:
url = app_configuration.base_urls.ws
if url is not None:
module = importlib.import_module(f'{app}.ws_urls')
dictionary = module.__dict__
app_urlpatterns = dictionary['urlpatterns']
url_router = URLRouter(app_urlpatterns)
ws_urlpatterns.append(
path(url, url_router)
)
return ws_urlpatterns
示例13: prepare_logging
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def prepare_logging(self, server, site_id):
"""
Populate the list of app-level loggers and handlers for both services
and apps
:param server: information required to generate log file path
:param site_id: information required to generate log file path
"""
self.service_logging_loggers = self._prepare_logging_loggers(
self.services
)
self.app_logging_loggers = self._prepare_logging_loggers(
self.apps
)
self.service_logging_handlers = self._prepare_logging_handlers(
self.services,
server,
site_id
)
self.app_logging_handlers = self._prepare_logging_handlers(
self.apps,
server,
site_id
)
示例14: test_nonmatching_urls
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def test_nonmatching_urls(self):
test_data = (
('int', {'-1', 'letters'}),
('str', {'', '/'}),
('path', {''}),
('slug', {'', 'stars*notallowed'}),
('uuid', {
'',
'9da9369-838e-4750-91a5-f7805cd82839',
'39da9369-838-4750-91a5-f7805cd82839',
'39da9369-838e-475-91a5-f7805cd82839',
'39da9369-838e-4750-91a-f7805cd82839',
'39da9369-838e-4750-91a5-f7805cd8283',
}),
)
for url_name, url_suffixes in test_data:
for url_suffix in url_suffixes:
url = '/%s/%s/' % (url_name, url_suffix)
with self.subTest(url=url), self.assertRaises(Resolver404):
resolve(url)
示例15: test_legacy_resolver_newstyle_django20_urlconf
# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import path [as 别名]
def test_legacy_resolver_newstyle_django20_urlconf():
from django.urls import path
url_conf = (path("api/v2/<int:project_id>/store/", lambda x: ""),)
resolver = RavenResolver()
result = resolver.resolve("/api/v2/1234/store/", url_conf)
assert result == "/api/v2/{project_id}/store/"