Using reverse(...)
is better than using reverse_lazy(...)
when the url is being reversed after URLConf
has been loaded.
Django looks up the URL name as defined in URLConf
to generate the URL. There are times when we want to use a URL before the URLConf
has been loaded, such as:
success_url
@permission_required('foo.bar', login_url=reverse_lazy(...))
If the URLConf
has been loaded there is no need to use reverse_lazy(...)
- just use reverse(...)
, becasue doing otherwise adds unecessary complexity.
If our GitHub code review bot spots this issue in your pull request it gives this advice:
1 | + | def my_view(request): | |
2 | + | url = reverse_lazy('foo') |
Using reverse(...)
is better than using reverse_lazy(...)
when the url is being reversed after URLConf
has been loaded.
- | url = reverse_lazy('foo') |
+ | url = reverse('foo') |