Domanda

I am using two domain names(.com and .mx) for a mezzanine project.When I am using the Site.objects.get_current() function for getting the current site id It return only one 1. whether I used .com OR .mx in my browser.

I think it is because in my settings.py the SITE_ID = 1 defined and when I edit it to 2 then Site.objects.get_current() function returns 2.

But what I actually wants is to define the templates by site , that is when user use .com then he will see a.html and when he use .mx he will see b.html.But as I told Site.objects.get_current() function gives me only one id whether I used .com or .mx , so I can't define the template by site.

So please suggest me some way to get dynamic site id or there is another way with which I can define template by site

È stato utile?

Soluzione

This is not exactly how the Sites framework works. To differentiate between sites using the sites framework, every site must have its own settings module (because that's where you set the SITE_ID).

What you are looking for is a way to get the current site from the request. You could use the RequestSite object for this:

from django.contrib.sites.models import RequestSite    
site_name = RequestSite(request).domain

There's also django-dynamicsites which does the same thing with a few more extras (redirects, template/url assignment, ...)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top