Project when using multiple sites

6 views
Skip to first unread message

Jay Parlar

unread,
Jul 31, 2006, 8:51:43 AM7/31/06
to django...@googlegroups.com
I've recently been looking at the docs, trying to grok the Sites framework.

What is the recommended way of laying out the filesystem when doing
multiple sites? Let's say I have two sites, "foo" and "bar", with URLs
foo.com and bar.com.

Would you put all the files for both sites into one Django project, or
would you give each its own project?

When I say "both sites into one Django project", I mean something like this:

myproject/
foo/
settings.py
urls.py
app1/
app2/
templates/
bar/
settings.py
urls.py
app3/
app4/
templates/

Then the vhost configurations for each site can point to the
individual settings files, the sites can potentially share
applications, and they can easily share models.

I suppose the same could be done by having each site in its own
project (after all, these are just Python packages and modules), but
it seems like I wouldn't want shared models crossing project domains
like that. That's just a purely conceptual idea though.

And that's the other thing, models. Say I have a model "Baz", that is
used by app1 in "foo", and by app3 in "bar". Where would I define it?
I would guess I can arbitrarily choose to define it in either
foo.models or bar.models. Or would it make any sense to define it
somewhere else entirely, so it's not directly coupled to only one app?

Thanks,
Jay P.

Jay Parlar

unread,
Jul 31, 2006, 9:04:28 AM7/31/06
to django...@googlegroups.com
Eww, the title of this thread was *supposed* to be "Project layout
when using multiple sites". Gotta remember to proof-read the subject
line before submitting!

Jay P.

Ian Holsman

unread,
Aug 2, 2006, 2:04:56 AM8/2/06
to django...@googlegroups.com
Hi Jay.

I have a similar issue.

I have stuff in http://zyons.com, which is open source, and another set of apps which build on top of it which run on multiple hosts. (http://gyspsyjobs.com & http://car-chatter.com for example)

the way I set it up is:


project/
common/
app1/
templates
app2/
templates
apps/
app3/
templates

these contain the standard way I think most people will use my code. the templates are in each app deal with the views the app does.

I then have 3 other template directories.
common_templates/
app_X_specific_templates/
site_NN/

common ones are usually stuff which I don't need to change that often (or ever) like the the Terms of Service (http://med-chatter.com/terms/ ) or privacy policy (http://med-chatter.com/privacy/ )
app specific templates are where I put boilerplates.. like a standard frontdoor for a given project-type. for example the "chat" series of sites are all based on the same front door, but other
apps I'm writing would have a completely different front door.

also in the "app" templates I put over-rides of  the common functionality. for example.. I have a non-OSS rating app where users can 'vote' on a given post (1-5) which I intend to use on top of the OSS 
forum app.
so I would put those templates in the app_X_specific_templates directory.

and obviously not all the sites are identical (they have different hostnames and possibly different things enabled for that site) .. they go in the site_NN directory.

I usually have a group of 'shared' URL roots.. 
url_app_X.py
and of course i have a set of N settings files which are hostname specific.
setting_hostname.py

so far this structure has worked for the 6-7 sites I run, and 3-4 projects I am using.


looking at it now, it all looks pretty complex.. but in reality most of the templates live in their corresponding 'app' directory with only one or two exceptions in various places.


regards
Ian.

Jay Parlar

unread,
Aug 2, 2006, 8:29:03 AM8/2/06
to django...@googlegroups.com
On 8/2/06, Ian Holsman <kry...@gmail.com> wrote:
>
> and obviously not all the sites are identical (they have different hostnames
> and possibly different things enabled for that site) .. they go in the
> site_NN directory.
>
> I usually have a group of 'shared' URL roots..
> url_app_X.py
> and of course i have a set of N settings files which are hostname specific.
> setting_hostname.py
>
> so far this structure has worked for the 6-7 sites I run, and 3-4 projects I
> am using.
>

Do you use the Sites framework for any of this though? That's the
thing I'm having a conceptual problem with.

More specifically, I'm not quite sure how to configure a project to
use the Sites framework. Namely, what to do with settings.py files? I
know to give each site unique SITE_ID values.

But then it *seems* that all the settings.py files have to have the
same SECRET_KEY, or I get a "User tampered with session cookie" error.

Also, how are we supposed to associate sites that we add through the
admin to a SITE_ID? The sites in the Admin don't actually show the
SITE_ID they're associated with.

I just can't seem to find any guidelines for configuring settings.py
properly to use the Sites framework.

Jay P.

Ian Holsman

unread,
Aug 2, 2006, 8:46:14 AM8/2/06
to django...@googlegroups.com
On 02/08/2006, at 10:29 PM, Jay Parlar wrote:


On 8/2/06, Ian Holsman <kry...@gmail.com> wrote:

and obviously not all the sites are identical (they have different hostnames
and possibly different things enabled for that site) .. they go in the
site_NN directory.

I usually have a group of 'shared' URL roots..
 url_app_X.py
and of course i have a set of N settings files which are hostname specific.
 setting_hostname.py

so far this structure has worked for the 6-7 sites I run, and 3-4 projects I
am using.


Do you use the Sites framework for any of this though? That's the
thing I'm having a conceptual problem with.
yes.
I have several 'sites' in a single DB.
but at the moment i'm questioning the usefulness of it, due to it having a common 'user' table, and the cost of adding a new database is quite small.
but to your question ;-)


More specifically, I'm not quite sure how to configure a project to
use the Sites framework. Namely, what to do with settings.py files? I
know to give each site unique SITE_ID values.

But then it *seems* that all the settings.py files have to have the
same SECRET_KEY, or I get a "User tampered with session cookie" error.

change the cookie name.
for example car-chatter.com has
SESSION_COOKIE_NAME ='revhead'
and
SESSION_COOKIE_NAME ='ithurtswhenidothis'

both sites have different SECRET_KEY and SITE_ID's.

Also, how are we supposed to associate sites that we add through the
admin to a SITE_ID? The sites in the Admin don't actually show the
SITE_ID they're associated with.
look at the URL in the admin tool
eg
http://car-chatter.com /admin/sites/site/6/
that is the SITE_ID (6).

i also have a line 
    r'/usr/local/src/magik/itscales/site_%d_templates' % SITE_ID,
in my TEMPLATE_DIRS which makes a bit easier ;-)


I just can't seem to find any guidelines for configuring settings.py
properly to use the Sites framework.

4 steps.

1. copy the settings.py to new-settings.py
2. add a site_id via the admin tool
3.  configure new-settings.py, changing the cookie name, SITE_ID, and SECRET_KEY as above
4. clone your httpd.conf with so that it uses new-settings.py on your host.

regards
Ian

Jay P.


--
Ian Holsman
join http://gyspsyjobs.com the marketplace for django developers 


Jay Parlar

unread,
Aug 2, 2006, 9:05:02 AM8/2/06
to django...@googlegroups.com

Perfect. These steps (and the SESSION_COOKIE_NAME) are exactly what
I've been looking for. Thanks Ian.

Jay P.

Reply all
Reply to author
Forward
0 new messages