While I can import models from another project if it is on PYTHONPATH,
I cannot find a way to share templatetags. I don't want to copy them,
because maintaining costs would become higher (need to remember to
apply bug fixes in both places, for example).
Is there a way to import templatetags from another project?
Django is really great framework, but I have a gut feeling that Django
support for code reuse is significantly worse, than, say, in Plone/
Zope 3. Though it might be because of my relative inexpirience in
Django.
I would be very grateful if someone will point me to pages/blog
entries about how to write Django apps with reusability in mind.
Eugene
Reuse is much easier once you think in terms of applications, rather
than projects. A project is just a collection of applications (really,
it's just a settings file and maybe a root URLConf). So you can easily
share an application in two projects, since applications can be imported
from anywhere on your Python path, as you've noted.
So, if you *only* want to share the template tags and nothing else from
their current application, make a new application that only contains
those template tags. Then you can install that application into both
projects (by including the import path in INSTALLED_APPS in each
project's settings file) and the code will be shared as you would
expect. As mentioned in a thread earlier today on this list, loading a
template tag in a template will cause all the installed apps to be
searched for that template tag file, so you don't need to worry about
keeping the tags right next to the templates they are used in.
> Django is really great framework, but I have a gut feeling that Django
> support for code reuse is significantly worse, than, say, in Plone/
> Zope 3. Though it might be because of my relative inexpirience in
> Django.
It's due to your inexperience, I suspect. Almost everything in Django
operates through normal Python imports, so you can share any code that
is on your Python path. The only real constraints are that template tags
are loaded from a directory called templatetags/ that must live in an
application directory and models must live in a module called "models".
Everything else is free-form and entirely under your control.
Regards,
Malcolm
--
Depression is merely anger without enthusiasm.
http://www.pointy-stick.com/blog/