Dear jaymzcd, I understand what the sites framework is used for and I have read through the Sites Frameworks documentation at least ten times. After a lot of experimentation I have found that my main problem is how i should specify my URL as I am working on my local machine.
I have set up my sub domain as: subdomain1.example.com Now if I wish to navigate to the index page of the above subdomain and specify my URL as subdomain1.example.com the URL takes the shape of http://127.0.0.1/subdomain1.example.com which is not what I want. Hence, my problem is creating a URL that will be recognised by urls.py and give me the domain name "subdomain1.example.com" in my views when the view executes the command Site.objects.get_current().domain. I have set up the view in question like this: -------------------------------------------------------------------------- # Create your views here. from django.contrib.sites.models import Site from django.conf import settings from django.template import Context, loader from django.shortcuts import render_to_response from django.http import HttpResponse def index(request): current_site = Site.objects.get_current() print current_site # do some stuff based on the current_site return render_to_response("main/index.html", {}) -------------------------------------------------------------------------- I think I first need to solve this before I start thinking about where to put my multiple settings.py files and so on. Thank you. Yours sincerely, Nanda On Jul 20, 11:52 pm, jaymzcd <jaym...@googlemail.com> wrote: > Have you been through everything > here:http://docs.djangoproject.com/en/dev/ref/contrib/sites/ > ? It goes through the whole process of working with thesitesframework, its > even encouraged to be used when running just a single > site. It sounds like you are making it more complicated that needs be. > If you just want to do one separate action for a certain subdomain you > can check the contents of request.META['SERVER_NAME'] and switch on > that in your view, but it sounds like you want to do separate things > per subdomain. The django docs really go go through it all. > > The purpose of thesitesframeworkis to have different domains that > may or may not have a completely different look and feel share the > same common core code. Thats why they have they're own settings.py > files, they're essentially separatesiteswith a common underbelly. > > jaymz > > On Jul 20, 5:55 am, nandu <navanitach...@gmail.com> wrote: > > > Could someone please help me and answer my question in the last email? > > > Thank you. > > Nanda > > > On Jul 19, 9:52 pm, nandu <navanitach...@gmail.com> wrote: > > > > Dear All, > > > > I have now set up my subdomains as separatesitesusing thesites > > >frameworkbut I have a few queries: > > > > 1. Does each site really require a separate django instance or can I > > > run all the subdomains on one instance? I have seven subdomains and > > > running seven django instances seems wasteful. > > > > 2. Currently I have a Django app corresponding to each subdomain since > > > each subdomain now needs a unique settings.py file is it ok to have > > > the settings file within the app or is it necessary for the app to > > > become a project in this case a project within a project? > > > > 3. Is it OK for me to put all my urls in the one single urls.py file > > > or would it be best to separate them on a per app basis. > > > > I just need a pointer in the right direction since I have never used > > > thesitesframeworkbefore, and as far as I know I could not find too > > > many tutorials or howtos on how touseit either. > > > > Thank you for all the help all of you have given me so far. > > > > Yours sincerely, > > > Nanda > > > > On Jul 19, 3:00 pm,nandu<navanitach...@gmail.com> wrote: > > > > > Thank you to all whohave replied. > > > > > I will give thesitesframeworkan honest effort and solve my problem. > > > > > Thank you very much for your time and effort. :-) > > > > > Nanda > > > > > On Jul 19, 2:42 pm, jaymzcd <jaym...@googlemail.com> wrote: > > > > > > Like Daniel & Steve have said already, urls.py only deals with the > > > > > path component of the URL, not the domain. Thesitesframeworkis what > > > > > you need touse, its pretty simple. All you really need to do is > > > > > something like: > > > > > > 1. in urls.py match the URL you want that is common for both > > > > > subdomains > > > > > 2. in your view for that pattern get the current site id > > > > > 3. based on what subdomain (site) is returned execute the appropriate > > > > > function > > > > > > urls.py *cant* know about the subdomain. If you have an aversion to > > > > > using thesitesframeworkyou could maybe hack it to work by looking > > > > > at the contents of request.META['SERVER_NAME'] in your view but i > > > > > wouldnt do that. Check thesitesframework... > > > > > > jaymz > > > > > > On Jul 19, 7:05 am,nandu<navanitach...@gmail.com> wrote: > > > > > > > Thank you to all who have replied to my query. > > > > > > > I do not think I need tousethesitesframeworkbecause my subdomains > > > > > > are not on different servers and hence are not really > > > > > > differentsites. > > > > > > Possibly what I am working with are actually pseudo-subdomains and > > > > > > not > > > > > > subdomains in the real sense. I will explain what I am intending to > > > > > > do > > > > > > below: > > > > > > > Let us say that I have a domain "example.com" > > > > > > > This site contains subdomains like the following: > > > > > > > subdomain1.example.com > > > > > > subdomain2.example.com > > > > > > > and so on. > > > > > > > In my urls.py if I want to map the subdomain1.example.com to some > > > > > > function and I need to know what regular expression I shoulduse. > > > > > > Another problem I am facing is that I testing this on localhost so I > > > > > > need to get a URL that I believe looks like "subdomain1.127.0.0.1: > > > > > > 8000" instead if "127.0.0.1:8000/subdomain1" and get urls.py to > > > > > > recognise this. I know that I may need to write a middleware class > > > > > > that intercepts every URL which I have implemented but I have no > > > > > > idea > > > > > > how to specify the URL in my href attribute in my link. > > > > > > > so that it is taken as subdomain1.127.0.0.1: 8000 instead of > > > > > > 127.0.0.1:8000/subdomain1 which is incorrect. > > > > > > > FYI > > > > > > I am working on a Ubuntu Linux machine and the Django development > > > > > > server. > > > > > > > I am sorry if I have misunderstood your answers above but IMHO I do > > > > > > not think I need tousethesitesframeworkas this is a fairly simple > > > > > > thing. > > > > > > > Thank you. > > > > > > > Yours sincerely, > > > > > > Nanda > > > > > > > On Jul 18, 1:47 am, Steve Holden <holden...@gmail.com> wrote: > > > > > > > > On 7/17/2010 12:38 PM,nanduwrote: > > > > > > > > > Dear Folks, > > > > > > > > > After researching the topic of using subdomains with Django I > > > > > > > > have > > > > > > > > found that it is does not seem to be a straight forward thing > > > > > > > > to do. > > > > > > > > > I have also found many websites showing methods of how to do > > > > > > > > this, but > > > > > > > > there is one aspect that none of them seem to explain. That is > > > > > > > > how > > > > > > > > does one specify the URL for the subdomain in urls.py if I had a > > > > > > > > subdomain like "something.example.com". > > > > > > > > > I would also appreciate it if someone could point me in the > > > > > > > > right > > > > > > > > direction in terms of how tousesubdomains with django as each > > > > > > > > website seems to specify a different method, and I have no idea > > > > > > > > which > > > > > > > > one is the best. The URLs of the websites I have looked at are > > > > > > > > below: > > > > > > > > >http://uswaretech.com/blog/2008/10/using-subdomains-with-django/ > > > > > > > > >http://thingsilearned.com/2009/01/05/using-subdomains-in-django/ > > > > > > > > >http://www.nerdydork.com/django-accounts-on-subdomains.html > > > > > > > > >http://djangosnippets.org/snippets/1119/ > > > > > > > > > I am also looking for a solution that avoids making many > > > > > > > > changes to > > > > > > > > the web application when it is about to be deployed. > > > > > > > > > Please forgive my ignorance in this matter. > > > > > > > > Servers in different subdomains are differentsites, so you may > > > > > > > want to > > > > > > > read up about Django'ssitesframework. > > > > > > > > http://docs.djangoproject.com/en/dev/ref/contrib/sites/ > > > > > > > > regards > > > > > > > Steve > > > > > > > -- > > > > > > > Steve Holden +1 571 484 6266 +1 800 494 3119 > > > > > > > DjangoCon US September 7-9, 2010 http://djangocon.us/ > > > > > > > See Python Video! http://python.mirocommunity.org/ > > > > > > > Holden Web LLC http://www.holdenweb.com/ > > > > > > > > -- > > > > > > > Tel/Toll-free: +1 571 484 6266 +1 800 494 3119 > > > > > > > DjangoCon US September 7-9, 2010 http://djangocon.us/ > > > > > > > See Python Video! http://python.mirocommunity.org/ > > > > > > > Holden Web LLC http://www.holdenweb.com/ -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.