1

i am writing a django app which i would like to be very loosely coupled and reusable. i was wondering what the best practices are if your app is going to be used in a larger project, and the app relied on something like jquery. how do you include jquery in your app but allow it to be overridden by the very likely event that the developer of the project already has jquery for the project?

1 Answer 1

3

You can add it through media class.

class Media:
        css = {
            'all': ('/static/css/styles.css',)
        }
        js = ['/static/js/jquery-1.6.2.min.js','/static/js/tiny_mce.js','/static/js/jquery.autocomplete.js','/static/js/ajax_select.js',]
Sign up to request clarification or add additional context in comments.

3 Comments

does this class hang off of a model class? it seems from the documentation that it does. i don't have a model class in my scenario because of the ajax. do you think you could give me a concrete example of this in use?
You can use this class in form class (child of django.forms.Form or django.forms.ModelForm) or in admin (child of django.contrib.admin.ModelAdmin).
Erm... As zaan says, you will need Django class which support Media class. If you haven't class at all, then you must write template tag, but it is look ungly. Code there is a code in my project, in ModelAdmin class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.