Include () and confusion in apartments

I follow Apress: Django Practical Projects , and I came across something that confuses me a bit.

When I configure url.py to point to flatpages, it works fine if I do this:

...
(r'', include('django.contrib.flatpages.urls')),
...

But that will not work. If I do this:

from django.contrib import flatpages
...
(r'', include(flatpages.urls)),
...

This tells me that:

An object

'module' has no attribute 'URL'

My knowledge of both Django and Python is quite limited, so this may be really obvious, but it would be nice to understand what is happening :)

thank

+3
source share
1 answer

He needs a variable urlpatternsfrom another module. So try:

from django.contrib import flatpages
...
(r'', include(flatpages.urls.urlpatterns)),
...

This is built into the example in django docs here .

Edit:

. - django.contrib, . from django.contrib.flatpages import urls.

, :

from django.contrib.flatpages import urls
...
(r'', include(urls.urlpatterns)),
...
+2

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


All Articles