#28691: Breaking change for 2.0: app_name no longer in include, but in urls.py
-------------------------------------+-------------------------------------
               Reporter:  Christian  |          Owner:  nobody
  Kreuzberger                        |
                   Type:             |         Status:  new
  Cleanup/optimization               |
              Component:             |        Version:  2.0
  Documentation                      |       Keywords:  breaking change,
               Severity:  Normal     |  documentation, app_name
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I believe I found a way to improve the documentation for the upcoming 2.0
 release. I found out about this as I had an old 1.8 app that I am trying
 to get compatible with 1.11 and 2.0.

 The "breaking changes" documentation in the 2.0 release notes states that

 * The {{{app_name}}} argument to {{{include()}}} is removed.

 However, it does not state that you now should (or even have to) specify
 the {{{ app_name }}} attribute in your urls.py.

 With Django 1.8 to 1.11 the following did work:

 myproject/urls.py:
 {{{
 from django.conf.urls import url, include
 from myproject.views import reset_password_request_token,
 reset_password_confirm

 urlpatterns = [
     url(r'^confirm', reset_password_confirm, name="reset-password-
 confirm"),
     url(r'^', reset_password_request_token, name="reset-password-
 request"),
 ]
 }}}

 Somewhere else in the main urls.py:
 {{{
 urlpatterns = [
     url(r'^api/password_reset/', include('myproject.urls',
 namespace='myproject')),
 ]
 }}}

 With 2.0 you will get the following error:

 {{{
  File "~/myproject/venv/lib/python3.5/site-packages/django/urls/conf.py",
 line 39, in include
     'Specifying a namespace in include() without providing an app_name '
 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.
 }}}


 The obvious fix is to specify {{{app_name}}} in myproject/urls.py like
 this:
 {{{
 from django.conf.urls import url, include
 from myproject.views import reset_password_request_token,
 reset_password_confirm

 app_name="myproject"

 urlpatterns = [
     url(r'^confirm', reset_password_confirm, name="reset-password-
 confirm"),
     url(r'^', reset_password_request_token, name="reset-password-
 request"),
 ]
 }}}

 I believe it might be worth adding this information to the list of
 breaking changes, stating that you have to specify the {{{app_name}}}
 attribute in your urls.py now. Might also be worth linking to the
 documentation for configuring urls.py properly, as {{{app_name}}} has been
 in there since 1.9:
 https://docs.djangoproject.com/en/2.0/topics/http/urls/#url-namespaces-
 and-included-urlconfs

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28691>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/059.beb3fdfbdc190dfad0f21e6ca83ad261%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to