Thursday, September 30, 2010

Re: Separating application media from project media

On 29/09/2010 18:55, Carles Barrobés wrote:
> At some point I also thought this was a good idea. This way I can
> reuse the app and all its visual stuff as well.
> But the problem is that for most cases you will want your templates
> and media to be consistent with a site's design and look&feel. This
> means that for two projects (sites) re-using the same application, the
> styles/icons etc are bound to be quite different. On the one hand it
> is already hard to create a template that can be reused in many
> different pages/layouts (normally for each site you will have a
> different base template and a specific template hierarchy, etc). And
> besides including specific stylesheets... which are bound to clash
> with styles from the base site...
> Unless you want to do something like the admin, which really looks
> like a different site and doesn't have anything to do with the rest of
> your site's look & feel, but which we don't care because we don't mind
> it really looking like a separate entity, since it is typically not
> available to end users.
> I don't know what your use case is and how you are going to tackle the
> difficulties I found. I in fact went the opposite way you're going,
> moving templates and styles to the project and keeping only the
> functionality for the app, because the templates and styles I needed
> ended up being quite coupled with the rest of the site.
> I'm interested to know how you solve this, or if it matters to you.
> Carles.

Hi Carles,

i find the whole project, app idea a bit confusing for my case.
It might help if I describe my use case first.

I'm building a set of applications that will be available to our users.
Users being company employees so no external users.
The start page is what I call a dashboard. It's basically a page with
tabs that represent different departments.
For instance ICT, Accountancy, and so on.
If you click on a tab, you'll see icons that link to a certain application.
For instance, you click on the ICT tab, you'll see an icon linked
to the calltracking application.

These applications are all very different. The first one, is a calltracking
system for ICT that allows users to see what we are doing for a certain
problem and allows us to follow up the calls.

The first problem i had was login. I want the users to login once
and if they switch to a different application, then they should remain
logged in.

That's how i ended up with a project "dashboard" and an application
"calltracking". The authentication code is located in the project, all
the calltracking files are in the calltracking directory.
Any other application, will be treated the same way as the calltracking.
Making an app and putting all related files in there.
The authentication for a new app is handled already then by the project.

A point of doubt i had when structuring the code was that the whole project/app
concept is clear when you talk about a site having a blog, a news app and so on.
But my applications are totally different and don't necessary belong to a "site".
The application IS a site. The only thing they have in common is the central login.
So style isn't an issue for me and a such, it makes more sense to put the media
and templates in the application directory.
This makes the application more portable.
But it still doesn't feel completely right.

The media is a problem however. I found a solution by putting a file
in the application directory. That settings file is imported in the projects settings file.
I've defined a MEDIA_URL & MEDIA_ROOT variable in the application settings file.
I actually named them MEDIA_URL_CALLTRACKING and
MEDIA_ROOT_CALLTRACKING and made a template tag that
makes them available in my calltracking templates.

I could have made a template context processor but that would make these
var's available in other applications and that didn't feel right so i choose
to use the template tag approach.
It works OK, but i could even make it simpler but that is very hackish:
in the tag, you can change the MEDIA_URL to the media URL of the caltracking.
Bonus: you can still use {{ MEDIA_URL }} in the templates instead of using
Like i said, this feels hackish and makes me doubt if i'm using the
whole project/app concept correctly.

If i would want to release my code for other people to use, it makes
more sense to distribute it as an application than as a project.
It's all confusion, that's why I think there should be a page on Django
that explains a few use cases and how code could then best be structured.

Another approach might have been to make a static dashboard page
instead of a project and make a project and app dir for every application.
But I don't know how I could manage a central login system then as
the cookies/sessions aren't shared across projects I think.

Anyway, i was able to put the templates and media in the application
in the end but since it was so much trouble, it probably means it's not
the way to go. If you want code on how i did it, shoot and I'll post it here.
There are only 2 things why i want to keep this code structure:
- the central login shared among applications
- if feels cleaner to share code if you're working with applications instead of

If i could do the login across projects, i would go for 1 application = 1 project.


You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment