Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 646267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:35:35+00:00 2026-05-13T21:35:35+00:00

Lets say we want a library of javascript-based pieces of functionality (I’m thinking jquery):

  • 0

Lets say we want a library of javascript-based pieces of functionality (I’m thinking jquery):
For example:

  1. an ajax dialog
  2. a date picker
  3. a form validator
  4. a sliding menu bar
  5. an accordian thingy

There are four pieces of code for each: some Python, CSS, JS, & HTML.

What is the best way to arrange all these pieces so that:

  • each javascript ‘module’ can be neatly reused by different views
  • the four bits of code that make up the completed function stay together
  • the css/js/html parts appear in their correct places in the response
  • common dependencies between modules are not repeated (eg: a javascript file in common)

x————–

It would be nice if, or is there some way to ensure that, when called from a templatetag, the templates respected the {% block %} directives. Thus one could create a single template with a block each for CSS, HTML, and JS, in a single file. Invoke that via a templatetag which is called from the template of whichever view wants it. That make any sense. Can that be done some way already? My templatetag templates seem to ignore the {% block %} directives.

x————–

There’s some very relevant gasbagging about putting such media in forms here http://docs.djangoproject.com/en/dev/topics/forms/media/ which probably apply to the form validator and date picker examples.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:35:35+00:00Added an answer on May 13, 2026 at 9:35 pm

    Been a while since I posted this problem. What I’ve been doing to solve it is:

    1. write the javascript parts you need as a library which is served statically
    2. call the routines in the static library from the template with your server side values

    Restraint is required to write it in such a way that it acts as a client side script only; don’t be tempted to try and inject values from the server at the time of serving the js. Ultimately I’ve found it less confusing to apply server side variables strictly in the html template.

    In this way I’m able to:

    1. keep the javascript selectors on html tags inside the same file (ie: the template)
    2. avoid templatetags altogether
    3. re-use each javascript library in different places, and
    4. keep the css/js/html pieces in all the places where they’re expected to be found

    It’s not perfect, but it’s getting me by till a neater idea comes along.

    For example a js library in “media/js/alertlib.js” might include:

    function click_alert(selector, msg){ 
        $(selector).click(function(){ alert(msg) })
    }
    

    and the template has:

    <script type="text/javascript" src="media/js/alertlib.js"></script>
    <script type="text/javascript">
        click_alert('#clickme', {% message %})
    </script>
    
    <div id='clickme'>Click Me</div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.