Skip to content

Commit c2ffaf0

Browse files
committed
Add app_name to rest_framework.urls.
This allows users in Django 1.9+ to include the authentication urls without specifying the namespace, as in: urlpatterns = [ ... url(r'^auth/', include('rest_framework.urls')) ]
1 parent f3949e9 commit c2ffaf0

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ If you're intending to use the browsable API you'll probably also want to add RE
8686
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
8787
]
8888

89-
Note that the URL path can be whatever you want, but you must include `'rest_framework.urls'` with the `'rest_framework'` namespace.
89+
Note that the URL path can be whatever you want, but you must include `'rest_framework.urls'` with the `'rest_framework'` namespace. You may leave out the namespace in Django 1.9+, and REST framework will set it for you.
9090

9191
## Example
9292

docs/tutorial/4-authentication-and-permissions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ And, at the end of the file, add a pattern to include the login and logout views
146146
namespace='rest_framework')),
147147
]
148148

149-
The `r'^api-auth/'` part of pattern can actually be whatever URL you want to use. The only restriction is that the included urls must use the `'rest_framework'` namespace.
149+
The `r'^api-auth/'` part of pattern can actually be whatever URL you want to use. The only restriction is that the included urls must use the `'rest_framework'` namespace. In Django 1.9+, REST framework will set the namespace, so you may leave it out.
150150

151151
Now if you open up the browser again and refresh the page you'll see a 'Login' link in the top right of the page. If you log in as one of the users you created earlier, you'll be able to create code snippets again.
152152

rest_framework/urls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
url(r'^auth/', include('rest_framework.urls', namespace='rest_framework'))
1010
]
1111
12-
The urls must be namespaced as 'rest_framework', and you should make sure
13-
your authentication settings include `SessionAuthentication`.
12+
In Django versions older than 1.9, the urls must be namespaced as 'rest_framework',
13+
and you should make sure your authentication settings include `SessionAuthentication`.
1414
"""
1515
from __future__ import unicode_literals
1616

@@ -19,6 +19,7 @@
1919

2020
template_name = {'template_name': 'rest_framework/login.html'}
2121

22+
app_name = 'rest_framework'
2223
urlpatterns = [
2324
url(r'^login/$', views.login, template_name, name='login'),
2425
url(r'^logout/$', views.logout, template_name, name='logout'),

0 commit comments

Comments
 (0)