本文整理汇总了Python中django.conf.urls.patterns方法的典型用法代码示例。如果您正苦于以下问题:Python urls.patterns方法的具体用法?Python urls.patterns怎么用?Python urls.patterns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.conf.urls
的用法示例。
在下文中一共展示了urls.patterns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def get_urls(self):
urls = super(DocumentSetAdmin, self).get_urls()
extra_urls = patterns('',
url('^(?P<document_set_id>\d+)/answers/$',
self.admin_site.admin_view(self.answers_view),
name="document_set_answers_csv"),
url('^(?P<document_set_id>\d+)/add_documents/$',
self.admin_site.admin_view(self.add_documents_view),
name='document_set_add_documents'),
url('^(?P<document_set_id>\d+)/update_canons/$',
self.admin_site.admin_view(self.update_canons_view),
name='document_set_update_canons'),
url('^(?P<document_set_id>\d+)/reverify_documents/$',
self.admin_site.admin_view(self.reverify_documents_view),
name='document_set_reverify_documents')
)
return extra_urls + urls
示例2: static
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def static(prefix, view='django.views.static.serve', **kwargs):
"""
Helper function to return a URL pattern for serving files in debug mode.
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
# ... the rest of your URLconf goes here ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
"""
# No-op if not in debug mode or an non-local prefix
if not settings.DEBUG or (prefix and '://' in prefix):
return []
elif not prefix:
raise ImproperlyConfigured("Empty static prefix not permitted")
return patterns('',
url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
)
示例3: get_url_patterns
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def get_url_patterns(self, ):
prefix = hasattr(self, 'prefix') and self.prefix or ''
url_patterns = [
url(r'^'+prefix+'$', self.perms['list'](self.get_list_class_view().as_view()), name=self.list_url_name, ),
url(r'^'+prefix+'create/$', self.perms['create'](self.get_create_class_view().as_view()), name=self.create_url_name ),
url(r'^'+prefix+'detail/(?P<pk>\d+)$', self.perms['detail'](self.get_detail_class_view().as_view()), name=self.detail_url_name ),
url(r'^'+prefix+'update/(?P<pk>\d+)$', self.perms['update'](self.get_update_class_view().as_view()), name=self.update_url_name ),
url(r'^'+prefix+'delete/(?P<pk>\d+)$', self.perms['delete'](self.get_delete_class_view().as_view()), name=self.delete_url_name ),
]
if django.VERSION >= (1, 8, 0):
return url_patterns
else:
from django.conf.urls import patterns
return patterns('', *url_patterns)
示例4: _buildPatternList
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def _buildPatternList():
urls = [
# Main website
url(r'^', include(SITE_URLS)) if SITE_URLS else None,
# Main app
url(r'^', include(MAIN_URLS)),
# Polychart.js website
url(r'^js/', include(JS_SITE_URLS)) if JS_SITE_URLS else None,
# Analytics
url('^', include(ANALYTICS_URLS)) if ANALYTICS_URLS else None,
# Deprecated URLs
url(r'^beta$', permanentRedirect('/signup')),
url(r'^devkit.*$', permanentRedirect('/')),
url(r'^embed/.*$', permanentRedirect('/')),
]
# Filter out None
urls = [x for x in urls if x]
return patterns('polychart.main.views', *urls)
示例5: _get_default_urlpatterns
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def _get_default_urlpatterns(self):
package_string = '.'.join(self.__module__.split('.')[:-1])
if getattr(self, 'urls', None):
try:
mod = import_module('.%s' % self.urls, package_string)
except ImportError:
mod = import_module(self.urls)
urlpatterns = mod.urlpatterns
else:
# Try importing a urls.py from the dashboard package
if module_has_submodule(import_module(package_string), 'urls'):
urls_mod = import_module('.urls', package_string)
urlpatterns = urls_mod.urlpatterns
else:
urlpatterns = patterns('')
return urlpatterns
示例6: patterns
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def patterns(*args):
return list(filter(lambda x: x, args))
示例7: get_sitemessage_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def get_sitemessage_urls() -> List:
"""Returns sitemessage urlpatterns, that can be attached to urlpatterns of a project:
# Example from urls.py.
from sitemessage.toolbox import get_sitemessage_urls
urlpatterns = patterns('',
# Your URL Patterns belongs here.
) + get_sitemessage_urls() # Now attaching additional URLs.
"""
url_unsubscribe = url(
r'^messages/unsubscribe/(?P<message_id>\d+)/(?P<dispatch_id>\d+)/(?P<hashed>[^/]+)/$',
unsubscribe,
name='sitemessage_unsubscribe'
)
url_mark_read = url(
r'^messages/ping/(?P<message_id>\d+)/(?P<dispatch_id>\d+)/(?P<hashed>[^/]+)/$',
mark_read,
name='sitemessage_mark_read'
)
if VERSION >= (1, 9):
return [url_unsubscribe, url_mark_read]
from django.conf.urls import patterns
return patterns('', url_unsubscribe, url_mark_read)
示例8: get_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def get_urls(self):
"""Add URLs needed to handle image uploads."""
urls = patterns(
'',
url(r'^upload/$', self.admin_site.admin_view(self.handle_upload), name='quill-file-upload'),
)
return urls + super(QuillAdmin, self).get_urls()
示例9: get_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def get_urls(self):
from django.conf.urls import patterns, url
urls = super(ClipboardAdmin, self).get_urls()
from .. import views
url_patterns = patterns('',
url(r'^operations/paste_clipboard_to_folder/$',
self.admin_site.admin_view(
views.paste_clipboard_to_folder),
name='filer-paste_clipboard_to_folder'),
url(r'^operations/discard_clipboard/$',
self.admin_site.admin_view(
views.discard_clipboard),
name='filer-discard_clipboard'),
url(r'^operations/delete_clipboard/$',
self.admin_site.admin_view(
views.delete_clipboard),
name='filer-delete_clipboard'),
# upload does it's own permission stuff (because of the stupid
# flash missing cookie stuff)
url(r'^operations/upload/(?P<folder_id>[0-9]+)/$',
self.ajax_upload,
name='filer-ajax_upload'),
url(r'^operations/upload/no_folder/$',
self.ajax_upload,
name='filer-ajax_upload'),
)
url_patterns.extend(urls)
return url_patterns
示例10: i18n_patterns
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def i18n_patterns(prefix, *args):
"""
Adds the language code prefix to every URL pattern within this
function. This may only be used in the root URLconf, not in an included
URLconf.
"""
pattern_list = patterns(prefix, *args)
if not settings.USE_I18N:
return pattern_list
return [LocaleRegexURLResolver(pattern_list)]
示例11: get_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def get_urls(self):
urlpatterns = super(ShippingApplication, self).get_urls()
urlpatterns += patterns('',
url(r'^city-lookup/(?P<slug>[\w-]+)/$', cache_page(60*10)(self.city_lookup_view.as_view()),
name='city-lookup'),
)
urlpatterns += patterns('',
url(r'^details/(?P<slug>[\w-]+)/$', cache_page(60*10)(self.shipping_details_view.as_view()),
name='charge-details'),
)
return self.post_process_urls(urlpatterns)
示例12: admin_view
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def admin_view(self, view, cacheable=False):
"""
Decorator to create an admin view attached to this ``AdminSite``. This
wraps the view and provides permission checking by calling
``self.has_permission``.
You'll want to use this from within ``AdminSite.get_urls()``:
class MyAdminSite(AdminSite):
def get_urls(self):
from django.conf.urls import patterns, url
urls = super(MyAdminSite, self).get_urls()
urls += patterns('',
url(r'^my_view/$', self.admin_view(some_view))
)
return urls
By default, admin_views are marked non-cacheable using the
``never_cache`` decorator. If the view can be safely cached, set
cacheable=True.
"""
def inner(request, *args, **kwargs):
if not self.has_permission(request) and getattr(view, 'need_site_permission', True):
return self.create_admin_view(self.login_view)(request, *args, **kwargs)
return view(request, *args, **kwargs)
if not cacheable:
inner = never_cache(inner)
return update_wrapper(inner, view)
示例13: get_urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def get_urls(self):
from django.conf.urls import patterns, url, include
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)
return update_wrapper(wrapper, view)
# Admin-site-wide views.
urlpatterns = patterns('',
url(r'^jsi18n/$', wrap(self.i18n_javascript,
cacheable=True), name='jsi18n')
)
# Registed admin views
urlpatterns += patterns('',
*[url(
path, wrap(self.create_admin_view(clz_or_func)) if type(clz_or_func) == type 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 self._registry.iteritems():
view_urls = [url(
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 += patterns('',
url(
r'^%s/%s/' % (
model._meta.app_label, model._meta.model_name),
include(patterns('', *view_urls)))
)
return urlpatterns
示例14: patch_root_urlconf
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def patch_root_urlconf():
from django.conf.urls import include, patterns, url
from django.core.urlresolvers import clear_url_caches, reverse, NoReverseMatch
from django.utils.importlib import import_module
try:
reverse('tasks:execute')
except NoReverseMatch:
root = import_module(settings.ROOT_URLCONF)
root.urlpatterns = patterns('', url(r'^tasks/', include('django_sae.contrib.tasks.urls', 'tasks',
'tasks')), ) + root.urlpatterns
clear_url_caches()
示例15: urls
# 需要导入模块: from django.conf import urls [as 别名]
# 或者: from django.conf.urls import patterns [as 别名]
def urls(cls):
base_name = cls.resource_name
return patterns('',
url(r'^$',
cls.list_view, name=base_name + '-list'))