Reversing URLs across services

16 views
Skip to first unread message

Noemi Millman

unread,
Jan 22, 2022, 8:07:09 AM1/22/22
to Django users
Hi folks --

Let's say you have two different services with different views and URLConfs; some shared modules/apps and some service-specific.  Is there a way for Service A to reverse URLs served by Service B without having to import all the dependencies that are necessary to execute Service B's views?

thanks,
-Noemi

Jason

unread,
Jan 22, 2022, 9:37:34 AM1/22/22
to Django users

yes, this is answered at https://stackoverflow.com/a/32171651

Noemi Millman

unread,
Jan 22, 2022, 7:46:45 PM1/22/22
to Django users
That answer is about reversing across apps, which I'm quite familiar with, and which still requires that the URL-owning app and its URLConfs be imported to the Django project where the reversing is being done.  The trouble is that the URLConf also has to import the views; which in turn won't import if all their dependencies are available. 

Thinking about it another way, I need to access a shared URLConf that doesn't need to import the view classes/functions that get called when a URL is actually accessed.  The information in the URLConf itself should be enough to reverse a URL, since the format and variables for each path are recorded in the URLConf.  But you can't create a URLConf without importing the views it calls; and Django will consider it invalid and refuse to parse/reverse those URLs for you if it doesn't have access to the views.

Is there any sensible way to work around that?
Reply all
Reply to author
Forward
0 new messages