Templates in a Multishop

27 views
Skip to first unread message

lifewithryan

unread,
Aug 25, 2009, 5:24:18 PM8/25/09
to Satchmo users
the more I delve into this, the more I start to sweat, but I know I'll
get through this. That being said --

I have a need to run the "Multi-Shop" functionality. My question is,
after reading some blog tutorials on GoSatchmo.com -- I think I have a
directory structure like the one mentioned in the project layout
tutorial:

/estore -- this is my main directory with settings.py, urls.py etc.
/appname -- my custom app holding my custom product
__init__.py, models.py, etc
/templates -- my templates
/shop -- copied over from satchmo
/product -- copied over from satchmo


My plan is that for my other "shops" i'll just add another "appname"
directory like above. Having said that, how do I ensure that my
templates remain unique on a per-site basis? (Meaning StoreA shouldn't
use the same templates as StoreB)

Is it simply a matter of having subdirs for each "app" under my
templates directory or should each app have its own templates
directory?

Sorry to keep posting so many questions, I've got a TON on my plate
and everywhere I start to code I run into other gotchas* that I want
to make sure I can handle...

(*gotchas being things like the paypal integration, some products and/
or categories being accessible from all stores instead of store
specific, etc...)

Bruce Kroeze

unread,
Aug 25, 2009, 6:01:49 PM8/25/09
to satchm...@googlegroups.com
On Tue, Aug 25, 2009 at 2:24 PM, lifewithryan<lifewi...@gmail.com> wrote:
>
> I have a need to run the "Multi-Shop" functionality.  My question is,
> after reading some blog tutorials on GoSatchmo.com -- I think I have a
> directory structure like the one mentioned in the project layout
> tutorial:
>
> /estore -- this is my main directory with settings.py, urls.py etc.
>    /appname -- my custom app holding my custom product
>       __init__.py, models.py, etc
>    /templates -- my templates
>       /shop -- copied over from satchmo
>       /product -- copied over from satchmo
>
>
> My plan is that for my other "shops" i'll just add another "appname"
> directory like above.  Having said that, how do I ensure that my
> templates remain unique on a per-site basis? (Meaning StoreA shouldn't
> use the same templates as StoreB)

You could use my "site-skins" module:
http://bitbucket.org/bkroeze/django-site-skins/

--
Bruce Kroeze
http://www.ecomsmith.com
It's time to hammer your site into shape.

Ryan Headley

unread,
Aug 25, 2009, 6:04:45 PM8/25/09
to satchm...@googlegroups.com
So its not as simple as just laying out a directory structure appropriately?

Damn, here I was thinking I could have app1 find its templates in templates/app1 and app2 find its templates in app2, etc.

I guess I had that impression from django itself -- *ugh*

Thanks for the link, I'll take a look.

Ryan
--
http://www.sudovi.com/
http://www.twitter.com/lifewithryan
http://www.thecommontongue.com
http://www.lifewithryan.com/

Alex Robbins

unread,
Aug 25, 2009, 6:18:32 PM8/25/09
to satchm...@googlegroups.com
If you really want the template looked up that way why not write your own template loader? Just pull the source from one of the existing loaders but don't look in so many places.

http://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types

Bruce Kroeze

unread,
Aug 25, 2009, 6:28:30 PM8/25/09
to satchm...@googlegroups.com
On Tue, Aug 25, 2009 at 3:18 PM, Alex
Robbins<alexander...@gmail.com> wrote:
> If you really want the template looked up that way why not write your own
> template loader? Just pull the source from one of the existing loaders but
> don't look in so many places.
>

That's basically what the site-skins app does.

FWIW, I think the original poster is confusing "apps" with sites. An
app is a component of a site, but is not itself a site.

Ryan Headley

unread,
Aug 25, 2009, 8:31:11 PM8/25/09
to satchm...@googlegroups.com
That's not a bad idea. I must ask however if I am misinterpreting the
point of the sites framework in django? If someone wants to run
multiple sites from one django instance is writing your own template
loader the way to keep templates separate? Just curious how others
are handling this (satchmo or not)
--
Sent from my mobile device

Alex Robbins

unread,
Aug 25, 2009, 9:27:06 PM8/25/09
to satchm...@googlegroups.com
Ok, if every site has its own settings.py file (and I think they have to, since SITE_ID is a setting), then you could just have a different TEMPLATE_DIRS setting for each site.

If you have two sites: store_a and store_b

store_a_settings.py
TEMPLATE_DIRS = (
    '/home/username/src/templates/store_a/',
    '/home/username/src/templates/generic/'
)

store_b_settings.py
TEMPLATE_DIRS = (
    '/home/username/src/templates/store_b/',
    '/home/username/src/templates/generic/'
)

http://docs.djangoproject.com/en/dev/ref/templates/api/#the-template-dirs-setting

That might accomplish what you are hoping for.

Ryan Headley

unread,
Aug 25, 2009, 11:40:18 PM8/25/09
to satchm...@googlegroups.com
Bruce,

You are correct, I am apparently mixing up "Sites" versus "Apps"

Basically, I have a large client that wants several store fronts all managed from one Satchmo instance.

I'm having trouble setting up the project such that Store A has its custom products as well as look/feel and Store B has its custom products as well as look/feel.


What I have is a project called "estore"
Underneath that I have the usual Django stuff.

My thought was I would create an "app" for each storefront to house the customized pieces.  In this case we'll stick with generics so
Underneath estore I have an app "StoreA" that has its own models inheriting from Satchmo's product module.

For now this is all well and good because they won't be launching the second store until later this year, so it gives me some time.  my thought was that I would start another app called "StoreB" that would have its own custom products (again extending from Satchmo's product model).  Where I am running into confusing is that StoreA will need a completely different set of customized templates than StoreB -- this is what I can't figure out.

I "could" kick off a process for each store and specify a different settings file for each "app" that only overwrites SITE_ID and TEMPLATE_DIRS, but that seems like it may not be the best way to go.  I've tackled that before using mod_python and a telling it a different settings file for each instance, but is that the best approach?


Pardon the rambling, its been a long night...

Ryan Headley

unread,
Aug 26, 2009, 12:07:50 AM8/26/09
to satchm...@googlegroups.com
To those following along at home -- I've had the Eureka moment.

will fill anyone interested in tomorrow...kid is crying

Bruce Kroeze

unread,
Aug 26, 2009, 12:10:41 AM8/26/09
to satchm...@googlegroups.com
On Tue, Aug 25, 2009 at 8:40 PM, Ryan Headley<lifewi...@gmail.com> wrote:

> Basically, I have a large client that wants several store fronts all managed
> from one Satchmo instance.
>

[...]


> my thought was that
> I would start another app called "StoreB" that would have its own custom
> products (again extending from Satchmo's product model).  Where I am running
> into confusing is that StoreA will need a completely different set of
> customized templates than StoreB -- this is what I can't figure out.

That's what site-skins does! It is very easy. You just make a "skin
directory" and put it in your settings.py file. Each top-level
directory in there is a "skin", which can be assigned to sites. The
template loader figures out which skin to use for each request, and
puts it at the top of the search order for templates.


> I "could" kick off a process for each store and specify a different settings
> file for each "app" that only overwrites SITE_ID and TEMPLATE_DIRS, but that
> seems like it may not be the best way to go.  I've tackled that before using
> mod_python and a telling it a different settings file for each instance, but
> is that the best approach?

No, I don't think so. I've also run into problems with mod_python
"leaking" memory between instances. If you go that way - with
separate settings files, you should definitely use fastcgi or mod_wsgi
and a standalone daemon for each store.

Ryan Headley

unread,
Aug 26, 2009, 12:16:24 AM8/26/09
to satchm...@googlegroups.com

Sorry, last one I promise -- (kid no longer crying)

I was indeed very confused about the Sites framework.  I was thinking that there was a way around having to have multiple mod_wsgi scripts and being able to run multiple sites from one "process" of django.  What I think is meant is that multiple sites using one django-project (and all its apps, etc).

It just so happened that my installation, each site is going to have its own app, and therefore I was seriously confusing myself.  I know now the my approach is:

site1.settings
site2.settings

and in each of those I specify the SITE_ID and the templates dir.  When I actually deploy -- my mod.wsgi script will be different for each vhost in apache.

I was thinking for some reason I could get away with just one mod_wsgi "process".

in my dev env, I will have to kick off serveral "manage.py runserver" processes using the --settings parameter to spedify different settings and set them to run on different ports...

(By the way this is all stuff I knew because we're doing it on another project, but I though we must be doing it wrong -- apparently we're not, thats how its done, so we were right for once).  I was thinking all along that there was a "better" way.

Thanks for your help everyone!

P.S.  I may still look into site skinz by Bruce, but for now, this way is finally clear to me when i think about it from the apache vhost perspective...
www.site1.com uses site1.settings
.www.site2.com uses site2.settings
each with their own wsgi handler script....
etc....
Reply all
Reply to author
Forward
0 new messages