I have a similar problem, app dev is at http://localhost/myapp/, deployment is at http://mywebsite.com/. I have added an URLBASE to settings.py and that's imported and used throughout my app. It would be nice for this to be created automatically by Django and made available through the API. Then again, I do use it in model get_absolute_url methods, which it wouldn't be exposed to if it goes through the request.

On a related point, how does get_absolute_url fit with the notion that models don't know about requests? This seems a violation of the oft-upheld principal to me. How come _pre_save can't know about the current user in the admin, but the same object is expected to know where the user should send requests to view this object? Is another layer required, one that handles all model functions for request contexts. The underlying model can be kept "pure" but better request- model interaction can be facilitated, taking inspiration from Zope3 adaptors perhaps.


On 13 Dec 2005, at 12:53, Amit Upadhyay wrote:

Hi,

I am developing an application and am soon going to deploy on another server but the URLs won't be exactly the same. There are many places I have to construct URLs, for linking to other pages in my application as well as for redirecting, and it is not clear to me how to do it in a portable fashion. One solution is to put a setting in settings.py, but is there another more standard way to specify what relative location my application will be deployed? I use 'include' and put my urls in my apps urls.py, and documentation says:

At any point, your urlpatterns can "include" other URLconf modules. This essentially "roots" a set of URLs below other ones.

If I could get this "root", it would be much more DRY than to define the 'root' and use another setting. Run the 'root' through s/ \^/\// before using it.

More concrete proposal:
Request contains a member: request.root, this contains urlregex encountered when an include was called; after a match has been found. This poses a problem of what to do if more than one includes are called as I believe its technically possible, and
one solution might be either to make request.roots a list of strings,
or django itself passes them through s/\^/\// and concatenates them together, which can directly be used by views to generate absolute URLs.

--
Amit Upadhyay
Blog: http://www.rootshell.be/~upadhyay
+91-9867-359-701


________________________________
** Cohack **
Pay-per-click campaign measurement, dashboard and analysis tools for online businesses. Customised Excel performance reports regularly emailed to key stakeholders.
http://www.cohack.com/?src=bgsig


Reply via email to