Django-rest-framework: Update tutorial to Django 2.0 url routing syntax

Created on 28 Apr 2018  路  6Comments  路  Source: encode/django-rest-framework

Hello everyone, newcomer to DRF here. I just started learning how to use DRF yesterday and noticed the tutorials (part 1 at least, not sure about the other parts) have not been updated to use the latest Django 2.0 URL routing syntax.

For example,

from django.conf.urls import url
from snippets import views

urlpatterns = [
    url(r'^snippets/$', views.snippet_list),
    url(r'^snippets/(?P<pk>[0-9]+)/$', views.snippet_detail),
]

should be

from django.urls import re_path
from snippets import views

urlpatterns = [
    re_path(r'^snippets/$', views.snippet_list),
    re_path(r'^snippets/(?P<pk>[0-9]+)/$', views.snippet_detail),
]

Alternatively, the path() function can be used. I'd be more than happy to help with updating the tutorials but I'm not sure how (never contributed to open source before). I assume I can start by cloning the repo, make the changes in the tutorial markdown files, and then make a pull request?

Most helpful comment

Thanks - I ran into this recently as well and documentation updates are a great way to break into open source.

The process you outlined is right, but I would also add checking out https://github.com/encode/django-rest-framework/blob/master/CONTRIBUTING.md#documentation which has more detail on how to build the docs site and formatting guidelines.

:+1: for path() function here since that's the default for a new Django 2.0 app already.

All 6 comments

Thanks - I ran into this recently as well and documentation updates are a great way to break into open source.

The process you outlined is right, but I would also add checking out https://github.com/encode/django-rest-framework/blob/master/CONTRIBUTING.md#documentation which has more detail on how to build the docs site and formatting guidelines.

:+1: for path() function here since that's the default for a new Django 2.0 app already.

Yup, that鈥檇 be a great place to start! It鈥檇 be a really nice improvement for us to make to that bit of the docs.

I assume I can start by cloning the repo, make the changes in the tutorial markdown files, and then make a pull request?

Yes, yes, and yes.

Feel free to make the pull request even if the work is still in progress, as that鈥檒l give us a good way to talk through any changes that need to be made along the way.

Also, as @metricmike mentions you might want to build the documentation locally to check your changes.

The most people still use older versions of Django. Are you sure that the docs still need be updated with the the path function? Pay attention that traditional url function is still available in Django 2.0 alongside with new 'path' function.

actually, the url function has been replaced with django.urls.re_path in Django 2.0. I would argue that it is a good idea to update the tutorial to 2.0 syntax, since newcomers will most likely install the latest version of Django alongside DRF when going through the tutorials. (that was the case for me at least).

I'd be happy to hear what other users have to say regarding this issue.

I agree on the fact that newcomers will try the path/re_path with urls as the Django's tutorial has already been updated.
Older developers should be confortable enough to preform the translation.

Closed via #5964. Loverly stuff.

Was this page helpful?
0 / 5 - 0 ratings