本文整理匯總了Python中django.conf.settings.ROOT_URLCONF屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.ROOT_URLCONF屬性的具體用法?Python settings.ROOT_URLCONF怎麽用?Python settings.ROOT_URLCONF使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.ROOT_URLCONF屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_apis
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def get_apis(self, url_patterns=None, urlconf=None, filter_path=None, exclude_namespaces=None):
"""
Returns all the DRF APIViews found in the project URLs
patterns -- supply list of patterns (optional)
exclude_namespaces -- list of namespaces to ignore (optional)
"""
if not url_patterns and urlconf:
if isinstance(urlconf, six.string_types):
urls = import_module(urlconf)
else:
urls = urlconf
url_patterns = urls.urlpatterns
elif not url_patterns and not urlconf:
urls = import_module(settings.ROOT_URLCONF)
url_patterns = urls.urlpatterns
formatted_apis = self.format_api_patterns(
url_patterns,
filter_path=filter_path,
exclude_namespaces=exclude_namespaces,
)
return formatted_apis
示例2: test_get_apis
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def test_get_apis(self):
urls = import_module(settings.ROOT_URLCONF)
# Overwrite settings with test patterns
urls.urlpatterns = self.url_patterns
apis = self.urlparser.get_apis()
self.assertEqual(self.url_patterns[0], apis[0]['pattern'])
self.assertEqual('/a-view/', apis[0]['path'])
self.assertEqual(self.url_patterns[1], apis[1]['pattern'])
self.assertEqual('/b-view', apis[1]['path'])
self.assertEqual(self.url_patterns[2], apis[2]['pattern'])
self.assertEqual('/c-view/', apis[2]['path'])
self.assertEqual(self.url_patterns[3], apis[3]['pattern'])
self.assertEqual('/a-view/child/', apis[3]['path'])
self.assertEqual(self.url_patterns[4], apis[4]['pattern'])
self.assertEqual('/a-view/child2/', apis[4]['path'])
self.assertEqual(self.url_patterns[5], apis[5]['pattern'])
self.assertEqual('/another-view/', apis[5]['path'])
self.assertEqual(self.url_patterns[6], apis[6]['pattern'])
self.assertEqual('/view-with-param/{var}/', apis[6]['path'])
示例3: test_get_apis_urlconf
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def test_get_apis_urlconf(self):
urls = import_module(settings.ROOT_URLCONF)
# Overwrite settings with test patterns
urls.urlpatterns = self.url_patterns
apis = self.urlparser.get_apis(urlconf=urls)
self.assertEqual(self.url_patterns[0], apis[0]['pattern'])
self.assertEqual('/a-view/', apis[0]['path'])
self.assertEqual(self.url_patterns[1], apis[1]['pattern'])
self.assertEqual('/b-view', apis[1]['path'])
self.assertEqual(self.url_patterns[2], apis[2]['pattern'])
self.assertEqual('/c-view/', apis[2]['path'])
self.assertEqual(self.url_patterns[3], apis[3]['pattern'])
self.assertEqual('/a-view/child/', apis[3]['path'])
self.assertEqual(self.url_patterns[4], apis[4]['pattern'])
self.assertEqual('/a-view/child2/', apis[4]['path'])
self.assertEqual(self.url_patterns[5], apis[5]['pattern'])
self.assertEqual('/another-view/', apis[5]['path'])
self.assertEqual(self.url_patterns[6], apis[6]['pattern'])
self.assertEqual('/view-with-param/{var}/', apis[6]['path'])
示例4: _post_teardown
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def _post_teardown(self):
""" Performs any post-test things. This includes:
* Putting back the original ROOT_URLCONF if it was changed.
* Force closing the connection, so that the next test gets
a clean cursor.
"""
self._fixture_teardown()
self._urlconf_teardown()
# Some DB cursors include SQL statements as part of cursor
# creation. If you have a test that does rollback, the effect
# of these statements is lost, which can effect the operation
# of tests (e.g., losing a timezone setting causing objects to
# be created with the wrong time).
# To make sure this doesn't happen, get a clean connection at the
# start of every test.
for conn in connections.all():
conn.close()
示例5: attempt_register
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def attempt_register(self, Model, ModelAdmin):
try:
admin.site.unregister(Model)
except admin.sites.NotRegistered:
pass
try:
admin.site.register(Model, ModelAdmin)
except admin.sites.AlreadyRegistered:
logger.warning("WARNING! %s admin already exists." % (
str(Model)
))
# If we don't do this, our module will show up in admin but
# it will show up as an unclickable thing with on add/change
importlib.reload(import_module(settings.ROOT_URLCONF))
clear_url_caches()
示例6: createTempViewURL
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def createTempViewURL():
# add the TempView to the urlpatterns
global urlpatterns
urlpatterns += [
url(r'^temp/?', TempView.as_view(), name='temp'),
]
# reload the urlpatterns
urlconf = settings.ROOT_URLCONF
if urlconf in sys.modules:
reload(sys.modules[urlconf])
reloaded = import_module(urlconf)
reloaded_urls = getattr(reloaded, 'urlpatterns')
set_urlconf(tuple(reloaded_urls))
# return the temporary URL
return reverse('temp')
示例7: background_serialization
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def background_serialization(self, exported_file_pk, rest_context, language, requested_fieldset, serialization_format,
filename, query):
# Must be here, because handlers is not registered
import_string(django_settings.ROOT_URLCONF)
prev_language = translation.get_language()
translation.activate(language)
try:
exported_file = self.get_exported_file(exported_file_pk)
exported_file.file.save(filename, ContentFile(''))
request = get_rest_request(exported_file.created_by, rest_context)
if settings.BACKGROUND_EXPORT_TASK_UPDATE_REQUEST_FUNCTION:
request = import_string(settings.BACKGROUND_EXPORT_TASK_UPDATE_REQUEST_FUNCTION)(request)
query = string_to_obj(query)
queryset = query.model.objects.all()
queryset.query = query
FileBackgroundExportGenerator(query.model).generate(
exported_file, request, queryset, RFS.create_from_string(requested_fieldset), serialization_format
)
finally:
translation.activate(prev_language)
示例8: get
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def get(self, request, *args, **kwargs):
ret = {}
# Get the version namespace
namespace = getattr(request.resolver_match, "namespace", "")
for ns in namespace.split(":"):
if re.match(r"v[0-9]+", ns, re.I):
namespace = ns
break
if self.urlconf:
urlconf = self.urlconf
else:
urlconf = import_module(settings.ROOT_URLCONF)
endpoints = get_api_endpoints(urlconf.urlpatterns)
for endpoint in sorted(endpoints, key=lambda e: e["pattern"].name):
name = endpoint["pattern"].name
if endpoint["method"] == "GET" and namespace in endpoint["namespace"].split(":"):
allow_cdn = getattr(endpoint["pattern"], "allow_cdn", True)
if not allow_cdn and settings.APP_SERVER_URL:
base = settings.APP_SERVER_URL
else:
base = request.build_absolute_uri()
try:
full_name = (
f'{endpoint["namespace"]}:{name}' if endpoint["namespace"] else name
)
path = reverse(full_name, *args, **kwargs)
except NoReverseMatch:
continue
full_url = urljoin(base, path)
ret[name] = full_url
return Response(ret)
示例9: _pre_setup
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def _pre_setup(self):
"""Performs any pre-test setup. This includes:
* Creating a test client.
* If the class has a 'urls' attribute, replace ROOT_URLCONF with it.
* Clearing the mail test outbox.
"""
self.client = self.client_class()
self._urlconf_setup()
mail.outbox = []
示例10: _urlconf_setup
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def _urlconf_setup(self):
if hasattr(self, 'urls'):
warnings.warn(
"SimpleTestCase.urls is deprecated and will be removed in "
"Django 1.10. Use @override_settings(ROOT_URLCONF=...) "
"in %s instead." % self.__class__.__name__,
RemovedInDjango110Warning, stacklevel=2)
set_urlconf(None)
self._old_root_urlconf = settings.ROOT_URLCONF
settings.ROOT_URLCONF = self.urls
clear_url_caches()
示例11: _post_teardown
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def _post_teardown(self):
"""Performs any post-test things. This includes:
* Putting back the original ROOT_URLCONF if it was changed.
"""
self._urlconf_teardown()
示例12: _urlconf_teardown
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def _urlconf_teardown(self):
if hasattr(self, '_old_root_urlconf'):
set_urlconf(None)
settings.ROOT_URLCONF = self._old_root_urlconf
clear_url_caches()
示例13: get_resolver
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def get_resolver(urlconf):
if urlconf is None:
from django.conf import settings
urlconf = settings.ROOT_URLCONF
return RegexURLResolver(r'^/', urlconf)
示例14: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def __init__(self, drf_router=None):
self.endpoints = []
self.drf_router = drf_router
try:
root_urlconf = import_string(settings.ROOT_URLCONF)
except ImportError:
# Handle a case when there's no dot in ROOT_URLCONF
root_urlconf = import_module(settings.ROOT_URLCONF)
if hasattr(root_urlconf, 'urls'):
self.get_all_view_names(root_urlconf.urls.urlpatterns)
else:
self.get_all_view_names(root_urlconf.urlpatterns)
示例15: process_request
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ROOT_URLCONF [as 別名]
def process_request(self, request):
urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
i18n_patterns_used, prefixed_default_language = is_language_prefix_patterns_used(urlconf)
language = translation.get_language_from_request(request, check_path=i18n_patterns_used)
language_from_path = translation.get_language_from_path(request.path_info)
if not language_from_path and i18n_patterns_used and not prefixed_default_language:
language = settings.LANGUAGE_CODE
translation.activate(language)
request.LANGUAGE_CODE = translation.get_language()