0

I am currently trying to get started with Django. But the book am using is using Django version <1.9 while the current version is >2.0

The problem am facing right now is this code:

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
url(r'^admin/', include(admin.site.urls)),
url(r'', include('learning_logs.urls', namespace = learning_logs'))
]

I have looked around and this is what I have written

from django.contrib import admin
from django.urls import include, path

app_name = 'learning_logs'
urlpatterns = [
    path('admin/', admin.site.urls),
    path('learning_logs/', include('learning_logs.urls', namespace = 'learning_logs')),
]

but when I run the server I get the error:

raise ImproperlyConfigured( django.core.exceptions.ImproperlyConfigured: Specifying a namespace in include() without providing an app_name is not supported. Set the app_name attribute in the included module, or pass a 2-tuple containing the list of patterns and app_name instead.

Any help with this. Thanks in advance

Andrews
  • 43
  • 7
  • Does this answer your question? [ImproperlyConfiguredError about app\_name when using namespace in include()](https://stackoverflow.com/questions/48608894/improperlyconfigurederror-about-app-name-when-using-namespace-in-include) – JPG Dec 02 '20 at 09:10

1 Answers1

0

In the learning/urls.py you need to set app_name = 'learning_logs. Not in the module that includes those urls.

BTW, you may want to run python with -Wd switch so that you get deprecation warnings sooner and you'll be able to maintain your code more easily.

gonczor
  • 3,994
  • 1
  • 21
  • 46
  • Thanks. And can you give sample code of how to run the `-Wd`. Am using windows. Thanks for the help. I will try it out and see what happens – Andrews Dec 02 '20 at 09:10
  • I guess it would be something similar. Maybe try `py -Wd manage.py runserver`. BTW, if I solved your problem, please mark this answer so that everyonen else knows it's a proper solution. – gonczor Dec 02 '20 at 10:02