The urls.py
in your project folder are the "base" URLs for your site.
You can then forward requests made on a certain route to your app's urls.py
using include
.
Here is an example :
# project's urls.py
from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('admin/', admin.site.urls),
path('myapp/', include("myapp.urls")) # requests on a route starting with "myapp/" will be forwarded to "myapp.urls"
]
And then in myapp.urls
:
# myapp's urls.py
from django.urls import path
from . import views
app_name = "myapp"
urlpatterns = [
path("", views.index, name="index"),
path("contact/", views.contact, name="contact")
]
So for instance, if I request "localhost:8000/myapp/contact", your project's urls.py
will detect that it must forward the request to your app myapp
, which will call its view views.contact
.