URL Namespaces Example

A snippet showing how to use URL namespaces in Django.


# models.py

from django.db import models

class Entry(models.Model):
    title = models.CharField(max_length=120)
      

# admin.py

from django.contrib import admin
from .models import Entry

@admin.register(Entry)
class EntryAdmin(admin.ModelAdmin):
    list_display = ("title",)
      

# project/urls.py
from django.urls import path, include
urlpatterns = [
  path("shop/", include(("shop.urls", "shop"), namespace="shop")),
  path("blog/", include(("blog.urls", "blog"), namespace="blog")),
]
#
# templates/example.html
<a href="{% url 'shop:cart' %}">Cart</a> | <a href="{% url 'blog:index' %}">Blog</a>
      
Explanation:
  • Use app namespaces to avoid name collisions across apps.
  • Reverse with namespace:name from templates and views.
  • Category URLs & Routing
  • Total Views 568
  • Last Modified 06 March, 2026
  • Tags #urls #namespaces #apps #routing
Previous snippet
Named URL Patterns
Next snippet
Slug Converter in URLs
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.