I came up with a general solution for PyCon (http://us.pycon.org/ apps07/schedule/)
The source code is here: https://svn.python.org/conference/django/trunk/pycon/templatetags/appmedia.py https://svn.python.org/conference/django/trunk/pycon/urls.py (for the dev server to serve up the static files) There are two minor bugs which need fixing, but it gets the job done. Just put your files in proj/myapp/media/ by default it will look in: ettings.MEDIA_URL + appname + '/' If they are served up in a custom location on the production server, in the settings file set the app media root: <APPNAME>_MEDIA_PREFIX = "url" # APPNAME is uppercase Example use in templates: https://svn.python.org/conference/django/trunk/pycon/schedule/templates/schedule/upload.html {% load appmedia %} <script type="text/javascript" src="{% app_media_prefix "schedule" %}js/timetables.js"></script> Hope that helps! -Doug On Mar 29, 1:37 am, Michael Lake <[EMAIL PROTECTED]> wrote: > Hi all > > Im trying Michael's suggestion quoted below for a custom tag but it's not > working so > I have tried a very very minimal one and it's not working either. > > In app/templatetags/template_extensions.py I have > from django.template import Library > register = Library() > > def mytag(): > return 'This is my tag.' > > mytag = register.simple_tag(mytag) > > Im my html file I have {% load template_extensions %} > and I have > MyTag is {{ mytag }} end. > > But I get MyTag is end. > i.e. nothing show. > > The template_extensions.py is being loaded cause if I make a deliberate > syntax error > in there I get a error message. > I can see > fromhttp://code.djangoproject.com/browser/django/trunk/django/contrib/adm... > how this is done and its so simple so I can't see whats wrong. > How can I track down the error? > > > > Michael wrote: > > In the mean-time, another method which seems to be used by the admin > > interface is to create your own template tag (using simple_tag). > > > If you take a look at the template tag used by the admin interface to > > create the {{ admin_media_prefix }} tag, it might give you some tips: > > > For your issue, I think you could copy and modify the code from / > > django_src/django/contrib/admin/templatetags/adminmedia.py to : > > > from django.template import Library > > > register = Library() > > > def url_root(): > > """ > > Returns the string for the root URL depending on the DEBUG > > setting. > > """ > > try: > > from django.conf import settings > > except ImportError: > > return '' > > if settings.DEBUG: > > return settings.URL_ROOT_DEBUG > > else: > > return settings.URL_ROOT > > > url_root() = register.simple_tag(url_root) > > > then your templates should just be able to use {{url_root}}. > > Mike > -- > Michael Lake --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---