Sometimes you want to name views so that you can refer to them by the name rather than by the url. That way, if the url changes in your app, you only need to update the code in one place (the urls.py
module). Existing code, which used the name rather than the url hardcoded, does not need to be updated.
For example, the reverse
utility function accepts this name and returns the url:
from django.urls import reverse
reverse('bar')
If you do not make use of the name, moving a route is cumbersome - you need to find and update the urls throughout all the templates and the code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…