What happens when I add a Django application to INSTALLED_APPS?

Here is the situation. I have a django project with two applications installed. Both applications work correctly if they are installed independently of each other.

However, if I list both applications in the .INSTALLED_APPS settings, the reverse () function seems to break for the URLs in the first application. Thus, it makes me think that an error in the second application is causing the problem.

If I just remove app_2 from settings.INSTALLED_APPS, app_1 url reverse () will start working again. So the question becomes what happens to “Magic” when I add app_2 to settings.INSTALLED_APPS? Where should I search in app_2 for the code causing this problem?

UPDATE:

I narrowed down the problem a bit, but it just gets weirder. app_2 has an admin.py file that defines several user views. This file contains a line that calls the opposite:
reverse('init_script_view', args=['id_content'])

As long as this line is in the admin.py file, all calls to reverse () end with the exception of NoReverseMatch. If I delete this line, everything will work fine.

+3
source share
2 answers

Nothing special happens if you add an application to INSTALLED_APPS, but the main thing that affects you is that its views are checked when called reverse().

, , URL-. , - - , reverse .

, 2, , - 2. , .

. . , - , admin urlconf, . admin.autodiscover() urls.py, .

+4

, , , urls.py app_1 app_2 URL-, :

app_1/urls.py:
  ...
  url(r'^app_1/foo/$', 'app_1.views.foo', name='foo')
  ...

app_2/urls.py:
  ...
  url(r'^app_2/foo/$', 'app_2.views.foo', name='foo')
  ...

( , , appname_viewname), .

0

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


All Articles