Does a call to urls.py through get_absolute_url() invoke views.py?

Since urls.py is the bridge between views.py and the templates which renders the pages (if I am wrong, correct me) and I try to get a link from it, does it call views?

Better still,
If i am listing the pages and i invoke get_absolute_url() (which value is returned via a reverse query in my model class) in the template,
in a bid to get the url pattern i specified in urls.py, does urls.py invoke views.py since it is not a request (that is, none of the links was clicked) or does it just return the urlpattern?

That’s not quite an accurate statement.

urls.py is the bridge between the application runtime environment (e.g. uwsgi, gunicorn) and your views.

Your view receives the request being passed to it by the runtime environment, and returns a response. (That is the simplest definition of what a view is.)

The response that your view returns might be an HTML web page. (It doesn’t need to be.) That web page being returned by your view could be rendered using a template. (But again, this is not a requirement. If your view is returning an HTML page, it could generate it itself without using a rendering engine on a template.

But to answer your question, no, neither the reverse functions nor the get_absolute_url function cause a view to be executed. It’s strictly a reference lookup into the url structures.

2 Likes