views:

54

answers:

2

I'm in the middle of developing an app on Google's App Engine, and one of the features is auth via Facebook Connect. I've got everything set up and working up to a certain level, but in order to test it against my dev machine, I've created a reverse proxy on one of my public facing servers that proxies through to the dev machine.

It all works fine except for most of the links are without the prefix I've created for the proxy.

So that got me thinking, is there an easy way to create a site-wide app prefix that not only works with my apps, but any 3rd party ones I want to use?

Is there some middleware I can include or a peice of the Django docs I've not read?

*Update: * Following the comment below, the prefix I'm thinking of goes in between then the domain name and the app url:

http://example.com/PREFIX/myapp/view/

A: 

if your prefix is in the domain name, why dont you use root-relative urls ?

i always use this kind of urls which is very handy

<a href="/myapp/view">blex</a>
<img src="/static/img/blex.png"/>

hope this helps.

jujule
No, the prefix needs to go in between the domain name and the actual apps urls.http://example.com/PREFIX/myapp/view for example
Stuart Grimshaw
what about defining a new settings.PREFIX = 'dev' that you can use in your urls ?
jujule
+1  A: 

Design the URLs for myapp to be standalone (such that its URLs can be 'included' in the URLs of another project).

urlpatterns = patterns ('',
    (r'^$', 'myapp.views.index'),
    (r'^view/$', 'myapp.views.view'),
    ...
)

Notice that you're not putting 'myapp' in your URLs at this point, but simply have a basic URL scheme that can be pointed wherever you want at deployment time.

Then, create a separate URLconf module for each target deployment (e.g., test vs. production) and use the django.conf.urls.defaults.include function to wire up the URLs to whatever arbitrarily deep base URL you want:

from django.conf.urls.defaults import *

urlpatterns = patterns('',
    (r'^PREFIX/myapp/', include('myapp.urls')),
    (r'^PREFIX/myapp2/', include('myapp2.urls')),
    (r'^PREFIX/myapp3/', include('myapp3.urls')),    
)

Point your deployment settings.py to use this URLconf module instead of pointing directly at the URL module for myapp.

Because my test environment looks quite different from my production environment, I like to have a separate settings module for each target deployment.

Joe Holloway
Thanks Joe, I'll just have to patch any 3rd party apps I want to use that don't let me work like this.Trouble comes when there are links etc in templates that don't know about my prefix.
Stuart Grimshaw
This is working quite well, and if anyone else is using it from behind a reverse proxy you can use (?:PREFIX/)? to make the prefix optional and it will respond locally without the prefix while you carry on developing.
Stuart Grimshaw