I'm interested in have for each app their own urls.py file and then, include them in the root urls.py file using the include django function like this include('myapp.urls')
.
Everything here follows the django tutorial: enter link description here
So, in root urls.py it is like this:
from django.url import include, path
urlpatterns = [ path('folio/', include('folio.urls')) ]
and now in the folio urls.py it is like the following:
from django.urls import path
from . import views
urlpatterns = [ path('', views.home, name='home') ]
After some tryings all I get is page not found.
What am I missing?
There's a variation to this to work, in this case I just need to import the app to the root urls.py as following:
from django.url import path
from folio import views
urlspatterns = [ path('', views.home, name='home') ]
The page error is very clear. No urls pattern is found in any of your views given your root url
'/'
orwww.example.com/
. Since your urls only includeadmin/
andfolio/
. No '/' was registered.But according to your workaround yes you must MAP A URL TO A PARTICULAR VIEW.
And in your case the
folio.views.home
is mapped. You might need to create a home view to renderbase.html
as homepage.urls.py
app_name/views.py
I also encourage todo an app namespacing, in your folio.urls.py before the
urlpatterns
add thisapp_name = 'folio'
So you can navigate to your folio app home using this url syntax in yourmain/templates/main/base.html
template.main/templates/main/base.html