Where can I find the source file "admin.site.urls"?

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

+6
source share
1 answer

In python, modules can be loaded from the __init__.py package; it should not be a file in the same directory.

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

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

site = AdminSite() (bottom)

  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 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: map urls get_urls ()

+11
source

Source: https://habr.com/ru/post/957874/


All Articles