| | 11 | def _detect_duplicate_urlnames(): |
| | 12 | ''' |
| | 13 | This function loads for each installed app the associated url file, it assumes that this this file is in the root |
| | 14 | of a project. Then it constructs a list of all urlnames and if it finds a duplicate urlname will raise an ImproperlyConfigured error |
| | 15 | ''' |
| | 16 | urlnames = [] |
| | 17 | for app in settings.INSTALLED_APPS: |
| | 18 | urlconf = app + '.urls' |
| | 19 | try: |
| | 20 | # Not all apps will necesarrily have a urls file, hence the try / except clause |
| | 21 | __import__(urlconf) |
| | 22 | urls = [] |
| | 23 | urls.append(sys.modules[urlconf]) |
| | 24 | for url in urls: |
| | 25 | for pattern in url.urlpatterns: |
| | 26 | name = getattr(pattern, 'name') |
| | 27 | if name == None: |
| | 28 | continue |
| | 29 | elif name not in urlnames: |
| | 30 | urlnames.append(name) |
| | 31 | else: |
| | 32 | raise ImproperlyConfigured('Duplicate named URL specified ("%s")' % name) |
| | 33 | except ImportError: |
| | 34 | pass |
| | 35 | |