This is my main urls.py:
urlpatterns = [
path('admin/', admin.site.urls),
path('', include("shop.urls")),
]
I want that any url entered by user will redirect to shop.urls and find there like if the user enters /index it will search index in shop.urls not in main urls.
My shop.urls:
from django.urls import path
from . import views
urlpatterns = [
path('', views.index),
path('index', views.index),
]
CodePudding user response:
In main urls:
just give route name.
urlpatterns = [
path('shop/', include("shop.urls")),
]
And this is your shop urls:
urlpatterns = [
path('index/', views.index),
]
After changing above code.
You can navigate like this in your browser:
localhost:8000/shop/index/
You will redirect to index page.
CodePudding user response:
You need to add /
at the end of route so:
urlpatterns = [
path('', views.index),
path('index/', views.index),
]
Then enter the requested url as http://127.0.0.1:8000/index/