我在哪里可以找到'admin.site.urls'的源文件?

时间:2022-05-21 15:05:47

In my urls.py, I have a line of codes of ('include(admin.site.urls). But I cannot find the source file in the setup dir of python like ..\site-packages\django\contrib\admin Where are they?

在我的urls.py中,我有一行代码('include(admin.site.urls)。但我找不到python的setup目录中的源文件,如.. \ site-packages \ django \ contrib \ admin他们在哪?

1 个解决方案

#1


11  

In python, modules can be loaded from within a package's __init__.py; it doesn't need to be a file in the same directory.

在python中,模块可以从包的__init__.py中加载;它不需要是同一目录中的文件。

If you look in django/contrib/admin/__init__.py you will see: from django.contrib.admin.sites import AdminSite, site

如果你查看django / contrib / admin / __ init__.py,你会看到:来自django.contrib.admin.sites import AdminSite,site

So then if you look in django/contrib/admin/sites.py you will see:

那么如果你查看django / contrib / admin / sites.py,你会看到:

site = AdminSite() (at the bottom)

site = AdminSite()(在底部)

def get_urls(self):
        from 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\d+)/(?P.+)/$',
                wrap(contenttype_views.shortcut),
                name='view_on_site'),
            url(r'^(?P\w+)/$',
                wrap(self.app_index),
                name='app_list')
        )

        # Add in each model's views.
        for model, model_admin in six.iteritems(self._registry):
            urlpatterns += patterns('',
                url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name),
                    include(model_admin.urls))
            )
        return urlpatterns

    @property
    def urls(self):
        return self.get_urls(), self.app_name, self.name

note: urls maps to get_urls()

注意:urls映射到get_urls()

#1


11  

In python, modules can be loaded from within a package's __init__.py; it doesn't need to be a file in the same directory.

在python中,模块可以从包的__init__.py中加载;它不需要是同一目录中的文件。

If you look in django/contrib/admin/__init__.py you will see: from django.contrib.admin.sites import AdminSite, site

如果你查看django / contrib / admin / __ init__.py,你会看到:来自django.contrib.admin.sites import AdminSite,site

So then if you look in django/contrib/admin/sites.py you will see:

那么如果你查看django / contrib / admin / sites.py,你会看到:

site = AdminSite() (at the bottom)

site = AdminSite()(在底部)

def get_urls(self):
        from 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\d+)/(?P.+)/$',
                wrap(contenttype_views.shortcut),
                name='view_on_site'),
            url(r'^(?P\w+)/$',
                wrap(self.app_index),
                name='app_list')
        )

        # Add in each model's views.
        for model, model_admin in six.iteritems(self._registry):
            urlpatterns += patterns('',
                url(r'^%s/%s/' % (model._meta.app_label, model._meta.module_name),
                    include(model_admin.urls))
            )
        return urlpatterns

    @property
    def urls(self):
        return self.get_urls(), self.app_name, self.name

note: urls maps to get_urls()

注意:urls映射到get_urls()