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)]
def get_urls(self): from my_django.conf.urls import patterns, url, include 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'^$', wrap(self.index), name='index'), url(r'^logout/$', wrap(self.logout), name='logout'), url(r'^password_change/$', wrap(self.password_change, cacheable=True), name='password_change'), url(r'^password_change/done/$', wrap(self.password_change_done, cacheable=True), name='password_change_done'), url(r'^jsi18n/$', wrap(self.i18n_javascript, cacheable=True), name='jsi18n'), url(r'^r/(?P<content_type_id>\d+)/(?P<object_id>.+)/$', wrap(contenttype_views.shortcut)), url(r'^(?P<app_label>\w+)/$', wrap(self.app_index), name='app_list')) # Add in each model's views. for model, model_admin in self._registry.iteritems(): urlpatterns += patterns( '', url( r'^%s/%s/' % (model._meta.app_label, model._meta.module_name), include(model_admin.urls))) return urlpatterns
def static(prefix, view='my_django.views.static.serve', **kwargs): """ Helper function to return a URL pattern for serving files in debug mode. from my_django.conf import settings from my_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), )
from __future__ import absolute_import from my_django.conf.urls import patterns from .feeds import feed_dict from .sitemaps import sitemaps urlpatterns = patterns( '', (r'^feeds/(?P<url>.*)/$', 'my_django.contrib.gis.views.feed', { 'feed_dict': feed_dict }), ) urlpatterns += patterns( 'my_django.contrib.gis.sitemaps.views', (r'^sitemap.xml$', 'index', { 'sitemaps': sitemaps }), (r'^sitemaps/(?P<section>\w+)\.xml$', 'sitemap', { 'sitemaps': sitemaps }), (r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kml$', 'kml'), (r'^sitemaps/kml/(?P<label>\w+)/(?P<model>\w+)/(?P<field_name>\w+)\.kmz$', 'kmz'), )
from my_django.conf.urls import patterns from .http import SimpleSitemap class HTTPSSitemap(SimpleSitemap): protocol = 'https' secure_sitemaps = { 'simple': HTTPSSitemap, } urlpatterns = patterns( 'my_django.contrib.sitemaps.views', (r'^secure/index\.xml$', 'index', { 'sitemaps': secure_sitemaps }), (r'^secure/sitemap-(?P<section>.+)\.xml$', 'sitemap', { 'sitemaps': secure_sitemaps }), )
def get_urls(self): from my_django.conf.urls import patterns return patterns('', (r'^(\d+)/password/$', self.admin_site.admin_view(self.user_change_password)) ) + super(UserAdmin, self).get_urls()
from my_django.conf.urls import patterns, url from my_django.contrib.formtools.tests.wizard.wizardtests.forms import ( SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4) urlpatterns = patterns( '', url( r'^wiz_session/$', SessionContactWizard.as_view([('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)])), url( r'^wiz_cookie/$', CookieContactWizard.as_view([('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)])), url( r'^wiz_other_template/$', CookieContactWizard.as_view([('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)], template_name='other_wizard_form.html')), )
from my_django.conf.urls import patterns, url from my_django.contrib.admindocs import views urlpatterns = patterns( '', url('^$', views.doc_index, name='django-admindocs-docroot'), url('^bookmarklets/$', views.bookmarklets, name='django-admindocs-bookmarklets'), url('^tags/$', views.template_tag_index, name='django-admindocs-tags'), url('^filters/$', views.template_filter_index, name='django-admindocs-filters'), url('^views/$', views.view_index, name='django-admindocs-views-index'), url('^views/(?P<view>[^/]+)/$', views.view_detail, name='django-admindocs-views-detail'), url('^models/$', views.model_index, name='django-admindocs-models-index'), url('^models/(?P<app_label>[^\.]+)\.(?P<model_name>[^/]+)/$', views.model_detail, name='django-admindocs-models-detail'), url('^templates/(?P<template>.*)/$', views.template_detail, name='django-admindocs-templates'), )
from my_django.conf.urls import patterns, include # special urls for flatpage test cases urlpatterns = patterns( '', (r'^flatpage_root', include('my_django.contrib.flatpages.urls')), (r'^accounts/', include('my_django.contrib.auth.urls')), )
@never_cache def add_template_response(request, message_type): for msg in request.POST.getlist('messages'): getattr(messages, message_type)(request, msg) show_url = reverse( 'my_django.contrib.messages.tests.urls.show_template_response') return HttpResponseRedirect(show_url) @never_cache def show(request): t = Template(TEMPLATE) return HttpResponse(t.render(RequestContext(request))) @never_cache def show_template_response(request): return TemplateResponse(request, Template(TEMPLATE)) urlpatterns = patterns( '', ('^add/(debug|info|success|warning|error)/$', add), ('^show/$', show), ('^template_response/add/(debug|info|success|warning|error)/$', add_template_response), ('^template_response/show/$', show_template_response), )
from my_django.conf import settings from my_django.conf.urls import patterns from my_django.core.urlresolvers import LocaleRegexURLResolver 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)] urlpatterns = patterns( '', (r'^setlang/$', 'my_django.views.i18n.set_language'), )
# The views used below are normally mapped in django.contrib.admin.urls.py # This URLs file is used to provide a reliable view deployment for test purposes. # It is also provided as a convenience to those who want to deploy these URLs # elsewhere. from my_django.conf.urls import patterns, url urlpatterns = patterns('', url(r'^login/$', 'my_django.contrib.auth.views.login', name='login'), url(r'^logout/$', 'my_django.contrib.auth.views.logout', name='logout'), url(r'^password_change/$', 'my_django.contrib.auth.views.password_change', name='password_change'), url(r'^password_change/done/$', 'my_django.contrib.auth.views.password_change_done', name='password_change_done'), url(r'^password_reset/$', 'my_django.contrib.auth.views.password_reset', name='password_reset'), url(r'^password_reset/done/$', 'my_django.contrib.auth.views.password_reset_done', name='password_reset_done'), url(r'^reset/(?P<uidb36>[0-9A-Za-z]{1,13})-(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', 'my_django.contrib.auth.views.password_reset_confirm', name='password_reset_confirm'), url(r'^reset/done/$', 'my_django.contrib.auth.views.password_reset_complete', name='password_reset_complete'), )
from my_django.conf.urls import patterns, include, url # Uncomment the next two lines to enable the admin: # from my_django.contrib import admin # admin.autodiscover() urlpatterns = patterns('', # Examples: # url(r'^$', '{{ project_name }}.views.home', name='home'), # url(r'^{{ project_name }}/', include('{{ project_name }}.foo.urls')), # Uncomment the admin/doc line below to enable admin documentation: # url(r'^admin/doc/', include('my_django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: # url(r'^admin/', include(admin.site.urls)), )
from my_django.conf.urls import patterns, url from my_django.contrib.formtools.tests.wizard.namedwizardtests.forms import ( SessionContactWizard, CookieContactWizard, Page1, Page2, Page3, Page4) def get_named_session_wizard(): return SessionContactWizard.as_view( [('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)], url_name='nwiz_session', done_step_name='nwiz_session_done' ) def get_named_cookie_wizard(): return CookieContactWizard.as_view( [('form1', Page1), ('form2', Page2), ('form3', Page3), ('form4', Page4)], url_name='nwiz_cookie', done_step_name='nwiz_cookie_done' ) urlpatterns = patterns('', url(r'^nwiz_session/(?P<step>.+)/$', get_named_session_wizard(), name='nwiz_session'), url(r'^nwiz_session/$', get_named_session_wizard(), name='nwiz_session_start'), url(r'^nwiz_cookie/(?P<step>.+)/$', get_named_cookie_wizard(), name='nwiz_cookie'), url(r'^nwiz_cookie/$', get_named_cookie_wizard(), name='nwiz_cookie_start'), )
from my_django.conf.urls import patterns urlpatterns = patterns('my_django.contrib.flatpages.views', (r'^(?P<url>.*)$', 'flatpage'), )
return render_to_response( 'context_processors/auth_attrs_messages.html', RequestContext(request, {}, processors=[context_processors.auth])) def userpage(request): pass # special urls for auth test cases urlpatterns = urlpatterns + patterns( '', (r'^logout/custom_query/$', 'my_django.contrib.auth.views.logout', dict(redirect_field_name='follow')), (r'^logout/next_page/$', 'my_django.contrib.auth.views.logout', dict(next_page='/somewhere/')), (r'^remote_user/$', remote_user_auth_view), (r'^password_reset_from_email/$', 'my_django.contrib.auth.views.password_reset', dict(from_email='*****@*****.**')), (r'^login_required/$', login_required(password_reset)), (r'^login_required_login_url/$', login_required(password_reset, login_url='/somewhere/')), (r'^auth_processor_no_attr_access/$', auth_processor_no_attr_access), (r'^auth_processor_attr_access/$', auth_processor_attr_access), (r'^auth_processor_user/$', auth_processor_user), (r'^auth_processor_perms/$', auth_processor_perms), (r'^auth_processor_messages/$', auth_processor_messages), url(r'^userpage/(.+)/$', userpage, name="userpage"), )
flatpage_sitemaps = { 'flatpages': FlatPageSitemap, } urlpatterns = patterns( 'my_django.contrib.sitemaps.views', (r'^simple/index\.xml$', 'index', { 'sitemaps': simple_sitemaps }), (r'^simple/custom-index\.xml$', 'index', { 'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap_index.xml' }), (r'^simple/sitemap-(?P<section>.+)\.xml$', 'sitemap', { 'sitemaps': simple_sitemaps }), (r'^simple/sitemap\.xml$', 'sitemap', { 'sitemaps': simple_sitemaps }), (r'^simple/custom-sitemap\.xml$', 'sitemap', { 'sitemaps': simple_sitemaps, 'template_name': 'custom_sitemap.xml' }), (r'^generic/sitemap\.xml$', 'sitemap', { 'sitemaps': generic_sitemaps }), (r'^flatpages/sitemap\.xml$', 'sitemap', { 'sitemaps': flatpage_sitemaps }), url(r'^cached/index\.xml$', cache_page(1)(views.index), { 'sitemaps': simple_sitemaps, 'sitemap_url_name': 'cached_sitemap' }), url(r'^cached/sitemap-(?P<section>.+)\.xml', cache_page(1)(views.sitemap), {'sitemaps': simple_sitemaps}, name='cached_sitemap'))
from my_django.conf.urls import patterns, include from my_django.contrib import admin urlpatterns = patterns( '', (r'^admin/', include(admin.site.urls)), )
""" This is a URLconf to be loaded by tests.py. Add any URLs needed for tests only. """ from __future__ import absolute_import from my_django.conf.urls import patterns, url from my_django.contrib.formtools.tests import TestFormPreview, TestWizardClass from my_django.contrib.formtools.tests.forms import (ContactWizard, Page1, Page2, Page3, TestForm, WizardPageOneForm, WizardPageTwoForm, WizardPageThreeForm) urlpatterns = patterns( '', url(r'^preview/', TestFormPreview(TestForm)), url( r'^wizard1/$', TestWizardClass( [WizardPageOneForm, WizardPageTwoForm, WizardPageThreeForm])), url(r'^wizard2/$', ContactWizard([Page1, Page2, Page3])), )
from my_django.conf.urls import patterns from my_django.contrib.databrowse import views # Note: The views in this URLconf all require a 'models' argument, # which is a list of model classes (*not* instances). urlpatterns = patterns( '', #(r'^$', views.homepage), #(r'^([^/]+)/([^/]+)/$', views.model_detail), (r'^([^/]+)/([^/]+)/fields/(\w+)/$', views.choice_list), (r'^([^/]+)/([^/]+)/fields/(\w+)/(.*)/$', views.choice_detail), #(r'^([^/]+)/([^/]+)/calendars/(\w+)/$', views.calendar_main), #(r'^([^/]+)/([^/]+)/calendars/(\w+)/(\d{4})/$', views.calendar_year), #(r'^([^/]+)/([^/]+)/calendars/(\w+)/(\d{4})/(\w{3})/$', views.calendar_month), #(r'^([^/]+)/([^/]+)/calendars/(\w+)/(\d{4})/(\w{3})/(\d{1,2})/$', views.calendar_day), #(r'^([^/]+)/([^/]+)/objects/(.*)/$', views.object_detail), )
from my_django.conf.urls import patterns, url urlpatterns = patterns('my_django.contrib.comments.views', url(r'^post/$', 'comments.post_comment', name='comments-post-comment'), url(r'^posted/$', 'comments.comment_done', name='comments-comment-done'), url(r'^flag/(\d+)/$', 'moderation.flag', name='comments-flag'), url(r'^flagged/$', 'moderation.flag_done', name='comments-flag-done'), url(r'^delete/(\d+)/$', 'moderation.delete', name='comments-delete'), url(r'^deleted/$', 'moderation.delete_done', name='comments-delete-done'), url(r'^approve/(\d+)/$', 'moderation.approve', name='comments-approve'), url(r'^approved/$', 'moderation.approve_done', name='comments-approve-done'), ) urlpatterns += patterns('', url(r'^cr/(\d+)/(.+)/$', 'my_django.contrib.contenttypes.views.shortcut', name='comments-url-redirect'), )
from my_django.conf.urls import patterns urlpatterns = patterns( 'my_django.views', (r'^(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'defaults.shortcut'), )