Django – extended URLs

cat extendedurls/urls.py 



from django.contrib import admin

from django.urls import path

from django.conf.urls import include, url

urlpatterns = [

    path('admin/', admin.site.urls),

    url('blogs.*/', include('blogs.urls')),

    url('mycontacts.*/', include('mycontacts.urls')),

]




cat mycontacts/urls.py 

from django.contrib import admin

from django.urls import path

from django.conf.urls import include, url

from mycontacts import views

urlpatterns = [

    url(r'whoami.*', views.whoami, name='whoami'),

    url(r'whoareyou.*', views.whoareyou, name='whoareyou'),

]

 cat mycontacts/views.py 

from django.shortcuts import render




# Create your views here.

from django.http import HttpResponse

from django.shortcuts import render

import operator




def whoareyou(request):

 return HttpResponse('Yes, I am the King!')




def whoami(request):

 return HttpResponse('Ohh ok ! Me too - the King!')



cat blogs/urls.py 

from django.contrib import admin

from django.urls import path

from django.conf.urls import include, url

from blogs import views

urlpatterns = [

    url(r'foods.*', views.foods, name='foods'),

    url(r'drinks.*', views.drinks, name='drinks'),

]

cat blogs/views.py 

from django.shortcuts import render




# Create your views here.

from django.shortcuts import render

  

# Create your views here.

from django.http import HttpResponse

from django.shortcuts import render

import operator


def drinks(request):

 return HttpResponse('Drink 4L waters a day to stay healthy')


def foods(request):

 return HttpResponse('Eat more green vegetables to stay healthy')




Try the following URLS -
http://127.0.0.1:8000/blogs-4-food/foods-which-is-healthy
http://127.0.0.1:8000/blogs-4-drinks/drinks-for-me
http://127.0.0.1:8000/mycontacts-in-india/whoami-please-tell-me
http://127.0.0.1:8000/mycontacts-in-uk/whoareyou-please-tell-me