On 2/07/2013 10:09am, Larry Martell wrote:
I have an app I distribute to clients.

When I run the app on my local machine I connect to http://127.0.0.1/...
When I'm VPN-ed into a client site I connect to the app on their
machine with http://xx.xx.xx.xx/...
When a client is running locally at their site they connect with
http://myappsname.company.com/....

I need to get that initial part of the URL from the python side. Is
there some way to do that? (I may be using the wrong terminology here
when I say 'url root'.)


Try this ...

import socket
def get_fully_qualified_domain_name():
    return socket.getfqdn()

This may or may not be what you want.

In any case, you will need to include the domain name of the host (to which you distribute your app) in settings.ALLOWED_HOSTS [1]

Additionally, you might want a utility method to return the desired url prefix in your get_absolute_url() methods. Perhaps like this if you use the contrib.sites app ...

from django.contrib.sites.models import Site
def get_domain():
    return Site.objects.get_current()

... which requires that you find some way to include the client domain in the Site table and insert that site.id into your various client's settings.SITE_ID

Alternatively, you could just parse the fully qualified domain name returned by socket.getfqdn() and use it in the above get_domain() or your get_absolute_url() methods.

[1] I follow the 2 scoops advice and have separate settings files for separate servers. I edit them manually for the very few servers my stuff runs on. AND I make sure the sites table is identical on all sites so I don't have to think about it ever again. YMMV.

Mike

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to