0

I'm confused by paths in Django.

In the source code for the 'Wiki' problem, the file "wiki/urls.py" has this code (1) in it:

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include("encyclopedia.urls"))
]

In the Django lecture (2020 version) at minute 18, Brian writes the following code for his overall project urls.py file. Within the project, he has a separate app called "hello" with this code (2) in the urls.py file.

urlpatterns = [
    path('admin/', admin.site.urls),
    path('hello/', include("hello.urls"))
]

Why does the code in (1) work? To reach encyclopedia.urls we need to go up a level in the file tree into the encyclopedia app, then into the urls.py file.

In (2) that travelling up a level in the file tree is done by

path('hello/', ... )

Or am I misunderstanding? How does Django know where to find the file it wants in (1)?

1 Answer 1

0

Django knows where to find the file required. In any include statement, the format is app.urls. If this app is installed (in the INSTALLED_APPS list of settings.py), then it goes to the folder and looks for urls.py. Then is adds the list of paths to that of the main urls.py with the path in prefix.

Hope this helps. If it does then please check the tickmark.

1
  • yes, thank you!
    – David S
    Commented Apr 18, 2021 at 13:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .