Hi Tomas,

Thanks again for your tips and code samples, I really appreciate it.

I really liked that technique of using __init__.py to add a constant
to the settings.py file. Very cool!

I get what you mean now when you say "I think hardcoding the 'app/'
directory is the usual way to do this, you should be the one naming
your /static/app/ directory anyways"... Here's my current solution:

Top of my widgets.py file:

from django.conf import settings

(I removed the crosshair function and put it in a JS file in my apps'
static folder)

class Media:
    js = (
        '%smy_app/my_app.js' % settings.STATIC_URL,
    )

In my_app.js, I link to crosshair.gif using a root-relative URI:

div.innerHTML = '<img src="/static/sound/crosshair.gif">';

(sometimes I wish JS could link to things relatively from the JS file
like css files do... Oh well, no harm in linking from the root path
here.)

With all that said, I did experiment with your suggestions. One
problem I ran into, was that os.path.dirname(__file__) returned a
server path to my apps' static folder (which is what I originally
asked for)... I soon remembered/realized that I needed a path to the
static collected folder, hence the use of the settings.STATIC_URL in
my widgets.py file.

Well, long story short (too late), as you can see, I did end up
hard-coding my app name into the widget file.

Like I said, I do like your technique of using __init__.py to add
vars/constants to the settings file. At one point, I was considering
doing something like this:

# __init__.py
settings.APP_NAME = 'my_app'
# Widget media JS:
'%s%s/location.js' % (settings.STATIC_URL, settings.APP_NAME),

But maybe that's serious overkill?

Anyway, many thanks for the inspiration and kick in the right direction. :)

Have an excellent night!

Cheers,
Micky

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to