Aninhando URLs com path, include e urls.py dos apps do Django
This commit is contained in:
8
aula207_ola_django/blog/urls.py
Normal file
8
aula207_ola_django/blog/urls.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from blog import views
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
# blog/
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.blog),
|
||||||
|
path('exemplo/', views.exemplo),
|
||||||
|
]
|
||||||
@@ -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')
|
||||||
|
|||||||
7
aula207_ola_django/home/urls.py
Normal file
7
aula207_ola_django/home/urls.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('', views.home),
|
||||||
|
]
|
||||||
@@ -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')
|
||||||
|
|||||||
@@ -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),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user