int - Matches zero or any positive integer. Returns an int.
str - Matches any non-empty string, excluding the path separator, '/'. This is the default if a converter isn’t included in the expression.
slug - Matches any slug string consisting of ASCII letters or numbers, plus the hyphen and underscore characters. For example, building-your-1st-django-site.
Example 1: Dynamic urls.
views.py from django.shortcuts import redirect, render def home(request): return render(request, 'home.html') def about(request, id): return render(request, 'about.html') def contact(request, id): return render(request, 'contact.html')
urls.py from django.contrib import admin from django.urls import path from mysite1 import views urlpatterns = [ path('admin/', admin.site.urls), path('home/', views.home), path('home/<int:id>', views.about), path('home/<str:id>', views.contact), path('home/<slug:id>', views.contact), ]
templates/home.html Home File
templates/contact.html Contact File