Mohamed Feddad

40%
Flag icon
Always name your patterns. It helps in decoupling your code from the exact URL paths. For instance, in the previous URLConf, if you want to redirect to the About page, it might be tempting to use redirect("/about"). Instead, use redirect("about"), as it uses the name rather than the path. Here are some more examples of reverse lookups:     >>> from django.urls import reverse     >>> reverse("hello_fn")     /hello-fn/     >>> reverse("year_view", kwargs={"year":"793"})     /year/793/    Names must be unique. If two patterns have the same name, they will not work.
Django Design Patterns and Best Practices: Industry-standard web development techniques and solutions using Python, 2nd Edition
Rate this book
Clear rating