Aninhando URLs com path, include e urls.py dos apps do Django

This commit is contained in:
Luiz Otávio
2023-04-16 14:57:04 -03:00
parent 4d721daa8d
commit e2be22efd8
5 changed files with 25 additions and 7 deletions

View File

@@ -0,0 +1,8 @@
from blog import views
from django.urls import path
# blog/
urlpatterns = [
path('', views.blog),
path('exemplo/', views.exemplo),
]

View File

@@ -5,4 +5,9 @@ from django.http import HttpResponse
def blog(request): def blog(request):
print('blog') print('blog')
return HttpResponse('blog do app') return HttpResponse('blog do app 1')
def exemplo(request):
print('exemplo')
return HttpResponse('exemplo do app 1')

View File

@@ -0,0 +1,7 @@
from django.urls import path
from . import views
urlpatterns = [
path('', views.home),
]

View File

@@ -5,4 +5,4 @@ from django.http import HttpResponse
def home(request): def home(request):
print('home') print('home')
return HttpResponse('home do app') return HttpResponse('home do app 1')

View File

@@ -14,13 +14,11 @@ Including another URLconf
1. Import the include() function: from django.urls import include, path 1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from blog import views as blog_views
from django.contrib import admin from django.contrib import admin
from django.urls import path from django.urls import include, path
from home import views as home_views
urlpatterns = [ urlpatterns = [
path('', home_views.home), path('', include('home.urls')),
path('blog/', blog_views.blog), path('blog/', include('blog.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]