This has been a topic of discussion quite recently -- see
http://code.djangoproject.com/ticket/15089 for details. Suffice to say
that this sort of problem is something we're aware of, and there are
people who have indicated an interest in looking at this in the 1.4
timeframe. If you're interested in this problem space, I encourage you
to get involved.
For the next couple of weeks the core developers will be a little busy
finalizing the 1.4 release; but you take that time to put together a
solid proposal (and maybe some sample code), you will be in good
position to make a big contribution when 1.4 development starts.
Yours,
Russ Magee %-)
That is obviously supposed to be 1.3 ;)
--
Łukasz Rekucki
Erm... ahh... No... I'm writing from the FUTURE!!! The flying cars are
awesome :-)
Russ %-)
So, here's what happened.
You all may remember that some time ago, as it was being brought
online for the first time, the Large Hadron Collider experienced...
difficulties. The exact nature of those difficulties was classified,
and a false story promulgated to cover it up. The LHC was offline for
over a year afterwards. A full explanation has been sent to Wikileaks,
but due to international pressure they have not yet released it. The
story can be told here for the first time.
As some of you may know, Russ is, in fact, *Dr.* Keith-Magee, holding
a Ph.D. in Artificial Intelligence. As the LHC team was moving to
bring the collider online, he used his -- in his words -- "mad
scientist" skills to access the LHC's command and control systems,
planting a moderately intelligent (able to pass the Turing Test with a
13-year-old) agent which subverted the collider to his nefarious
purposes, specifically the production of tachyons from extremely
high-speed collisions.
The test fire which caused extensive damage to the LHC also produced a
massive burst of tachyons, which -- as particles which travel
backwards through time, per Einstein's theories -- carried information
from the future. By careful observation of these tachyons, Russ was
able to glean information about the future of Django (transmitted
using an elegant encoding scheme based on quantum-mechanical
properties of the tachyons -- by observing one set of properties, he
could
determine the ID of a fixed ticket, and by observing a different set
of properties he could determine the date on which it was fixed).
This information was then forwarded to the private Django committers'
list, and Russ himself has gone into hiding until the future date on
which he will encode the information to be transmitted back to the
past.
As a result, we don't currently have Django running on Python 3, but
we do know the details of when and how it will happen. A full write-up
of how we accomplished the porting, and a timeline of when we did and
will port, will appear in the near future on the Django Advent site
for 1.3. The primary holdup at this time is an investigation of
whether our foreknowledge of the future timeline (as evidenced by a
mysterious application which appears in far-future tickets, named
"django.contrib.lightcones") will in any way alter it.
Anyway. Now you know, and knowing is half the battle.
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
I also started to have a look at something similar (ie, with settings for each site).
The proposal made in the ticket wouldn't fit what you are trying to do.
The current idea is to have the site id depends on the request but assumes to have only one common settings file.
On the other hand, having one setting file per site where the only difference is the site id seems a bit too much overhead.
Regards,
Xavier.
> --
> You received this message because you are subscribed to the Google Groups "Django developers" group.
> To post to this group, send email to django-d...@googlegroups.com.
> To unsubscribe from this group, send email to django-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
>
Why not use something like this:
from global_settings import *
SITE_ID = 235
#This also allows further changes like:
#INSTALLED_APPS = INSTALLED_APPS + (
# 'fooapp',
#)
I'm using something similar here, but the number of sites I need to run
with the same codebase is rather limited (unter 10). Anyways it works
well.
In addition every site has its own python module here, so changing the
settings is just a small step...its even possible to have different
urlconfs or templates or ...
David
As for the urlconf, it's already possible. core/urlresolvers have a set/get urlconf that is set for the thread by the BaseHandler.
Don't get me wrong, I started some work in order to have each site with its own settings.
However, this seems to differ from what was done in ticket 15089.
This only things that troubles me is that one shouldn't be able to set INSTALLED_APPS per site because I can't see how syncdb would perform with new apps.
Xavier.
I suggest to have a look to www.reviewboard.org since they have solved
this problem a long time ago.
> I have currently FlatPage app
> running perfectly with this, only thing I needed to change from
> flatpage view was following:
> ...
> # Get request's site id, fallback to settings.SITE_ID
> site_id = getattr(request, 'site_id', settings.SITE_ID)
> f = get_object_or_404(FlatPage, url__exact=url,
> sites__id__exact=site_id)
> ...
>
> I think this SITE_ID per request is a great idea, worth thinking for
> Django itself.
>
request.META['HTTP_HOST'] is also the primary mechanism for
determining which website to serve when doing virtual hosting, IE if
you use apache and your site is hosted in a structure like:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.foo.com
ServerAlias *.foo.com *.bar.com *.quuz.com
....
</VirtualHost>
Then that variable already is being verified.
Cheers
Tom
I have one question about changing the site ID per request.
I assume that settings is imported from conf, and so in the end it is simply changing the same SITE_ID to fit the current request Django is handling.
Does this ever become a problem? I am setting up around 250 sites for example. If the site_id had a conflict because it is trying to be changed in two places at the same time.
On Jan 27, 3:16 pm, Graham Dumpleton <graham.d...@gmail.com>
wrote:
> On Friday, January 28, 2011 2:09:06 AM UTC+11, Tom Evans wrote:
>
> > On Wed, Jan 26, 2011 at 6:18 PM, Jari Pennanen <jari...@gmail.com>
> > wrote:
As you can see, it makes SITE_ID a thread-local property which has a different value for every thread.
Hope this helps someone.
Bye,
Waldemar
... and this is one of the biggest reasons why Django doesn't
encourage the practice of using threadlocals.
If an engineer came to their supervisor with a problem and said "I'm
going to fix this problem with a global variable", they would be
soundly beaten by any supervisor worth their salt. Somehow, because
the name has been changed to "threadlocal", global variables have
suddenly become acceptable.
Every single problem associated with using global variables exists
with threadlocals -- and then a few more. They *can* be used
successfully. However, in almost every case, they can also be avoided
entirely with a good dose of rigorous engineering.
I *strongly* advise against the use of this technique.
Yours,
Russ Magee %-)
I understand (and completely support) your objection, specially when
someone says «one could save even the request object to thread
"global" and it would be accessible anywhere.» (which would make code
using requests, i.e. a lot of it harder to reuse and to test)
But the core problem being solved here, about moving SITE_ID to a
threadlocal, doesn't look like bad engineering to me. In fact is
moving something that is already global (everything in settings.py is)
to alocation which is *less* global (thread-wise instead of
process-wise). So this is an increase in locality, if I got it
right...
In which way is this worse than the current state of a global
variable? (and in general, do you have some reference to explain
«Every single problem associated with using global variables exists
with threadlocals -- and then a few more»? I tend to think that a
thread local is generally better than a global, even if it tends to be
worse that good API design/argument passing)
Regards,
D.
This post is getting pretty long. But I had a simple Django fix that would make it work a lot easier for me, and might help others. (I say this because of how I implemented it, I am working with about 60 different sites and it is a pretty simple arrangement)Imagine you were able to set a site_id per request rather than relying on the settings SITE_ID. Django would then checked for a request's site_id first and then second check the settings one.It is really simple, but it would fix a lot of my problems and avoid having to switch around the settings SITE_ID per request. Setting the requests site_id with middleware is straightforward enough and further customizations to the request. Changing the urls for example.This approach would avoid:
- Threading issus, and global variables
- Adding new functions to work with (Saves time and pain, documentation, testing, releases so forth)
- Doesn't break things that are tied into the Sites Framework(site-maps, comments, etc...)
It also feels a little more DRY to me.Let me know if I have assumed something I shouldn't have. I don't know much about how the current implementation and use of SITE_ID in the backend.Cheers,James Hancock