Reputation: 127
I'm following a django tutorial that is a little outdated and in the urls.py file of the first app's directory we need to configure where to direct django to for any url starting with 'notes/'. There are two separate 'apps' inside the project. I'm in the first one, not notes.
This is the code currently. I added include
to import statement:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path(url(r’^notes/‘, include('notes.urls'))),
]
Inside the urlpatterns object, on the first line, path('admin/', admin.site.urls)
, comes predefined, but I need to add a redirect such that django goes to a different app, called 'notes' and searches there for its entry point, since all of the urls will begin with ‘notes/’.
The tutorial says to use a regular expression and uses this code:
url(r’^notes/‘, include(notes.urls))
so that any url that starts with 'notes/' should be redirected to this other file notes.urls
.
However the predefined ones that currently come out of the box with a django project start with path
.
I enclosed my notes/n redirect line in path, but not sure if this is correct. Should I instead directly write:
url(r’^notes/‘, include(notes.urls))
Also, do I need to delete the first line provided?
path('admin/', admin.site.urls),
The tutorial has:
urlpatterns = patterns('',
url(r’^notes/‘, include(notes.urls)),
)
and no admin urls line. It's from 2014 I believe.
Upvotes: 0
Views: 1281