當前位置: 首頁>>代碼示例>>Python>>正文


Python settings.ROOT_URLCONF屬性代碼示例

本文整理匯總了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 
開發者ID:Arello-Mobile,項目名稱:py2swagger,代碼行數:26,代碼來源:urlparser.py

示例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']) 
開發者ID:Arello-Mobile,項目名稱:py2swagger,代碼行數:21,代碼來源:test_urlparser.py

示例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']) 
開發者ID:Arello-Mobile,項目名稱:py2swagger,代碼行數:21,代碼來源:test_urlparser.py

示例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() 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:20,代碼來源:testcases.py

示例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() 
開發者ID:propublica,項目名稱:django-collaborative,代碼行數:18,代碼來源:admin.py

示例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') 
開發者ID:iguana-project,項目名稱:iguana,代碼行數:19,代碼來源:test_login.py

示例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) 
開發者ID:matllubos,項目名稱:django-is-core,代碼行數:23,代碼來源:tasks.py

示例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) 
開發者ID:mozilla,項目名稱:normandy,代碼行數:40,代碼來源:views.py

示例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 = [] 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:12,代碼來源:testcases.py

示例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() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:13,代碼來源:testcases.py

示例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() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:8,代碼來源:testcases.py

示例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() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:testcases.py

示例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) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:7,代碼來源:urlresolvers.py

示例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) 
開發者ID:manosim,項目名稱:django-rest-framework-docs,代碼行數:14,代碼來源:api_docs.py

示例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() 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:11,代碼來源:locale.py


注:本文中的django.conf.settings.ROOT_URLCONF屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。