views:

48

answers:

2

I can't, for the life of me, get Django to find my JavaScript files! I am trying to plug in a custom widget to the admin page, like so:

class MarkItUpWidget(forms.Textarea):
class Media:
    js = (
        'js/jquery.js',
        'js/markitup/jquery.markitup.js',
        'js/markitup/sets/markdown/set.js',
        'js/markitup.init.js',
    )
    css = {
        'screen': (
            'js/markitup/skins/simple/style.css',
            'js/markitup/sets/markdown/style.css',
        )
    }

However, when this code is inserted on my admin page, all of the links are broken, I can't get to any of my JavaScript files. My settings file looks like this: http://pastebin.com/qFVqUXyG

Is there something I am doing wrong? I'm somewhat new to Django.

+3  A: 

I guess you're using django-admin runserver to test your website. In that case, have a look at "How to serve static files" (but don't ignore the big fat disclaimer).

Once you're ready to deploy, this chapter contains all the information (provided you go the standard route of Apache/mod_wsgi)

piquadrat
A: 

I don't know what the "django way" to include js files is, but I just use a simple regular include in the template, its great since you can dynamically generate the location / filename for these.. oh and if you are using django's test server I don't know how to get it to recognize these or if it even can but all you need is to run an apache server on your local machine and then put the files in the localhost directory and you can include them through localhost by including their full path in the template (i.e., http://localhost/myfiledirectory/myfile.js), also something I do is use amazon s3 to host files since you then get a url for them on there (not that you asked about this but its a quick way to host files if you don't have apache running locally)

Basically, my understanding of Django is that it works differently than a PHP framework, for example, as the files for Django don't sit (or don't need to at least) in the web path (i.e. they do not need to be accessible through the host path but can be anywhere on the machine) this is good for providing extra security, etc but it also means, that to give files a url to download them they need to be in the web hosting path, others may know how to make django do this directly but my quick and dirty method of putting them on the localhost path will work if thats all you're after.

Rick