Reputation: 771
Recently I started my web project using Django with reference to some youtube tutorials. I have created a project named admin and created an app named user. From many tutorials they have created separate urls.py
for both project and app. But in my case only the project's urls.py
is working.
For example, I have defined the index view (my home page) in project's urls.py
and login view in app's urls.py
. When I try to access the login as it shows:
The current path, login, didn't match any of these
Can anyone help me to find out the solution for this?
Upvotes: 0
Views: 81
Reputation: 46
Django only checks the URLs of the project's ROOT_URLCONF
e.g. urls.py
. If you want to include the URLs of a certain app, you can do the following:
In your projects urls.py
:
from django.urls import include, path
urlpatterns = [
path('user/', include('user.urls')),
# others...
]
Then, if you go to url yoursite.com/user/
, it will find the URLs specified in the app's urls.py
. For more information see the docs.
Also make sure that your app user
is in the INSTALLED_APPS
of your settings.py
, like this:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
...
'user',
...
]
So that django knows about your app.
Upvotes: 2