0

here Javascript code is not displaying in Django. even before I did lot of research on it but unable to find. I really don't know what to do here. please anyone guide me how to do this. This help will be precious for me.

static/js/script.js:

var bar = new ProgressBar.Circle(container, {
    color: '#ff0000',
    // This has to be the same size as the maximum width to
    // prevent clipping
    strokeWidth: 4,
    trailWidth: 1,
    easing: 'easeInOut',
    duration: 10000,
    text: {
      autoStyleContainer: false
    },
    from: { color: '#ff0000', width: 5 },
    to: { color: '#00cc00', width: 9 },
    // Set default step function for all animate calls
    step: function(state, circle) {
      circle.path.setAttribute('stroke', state.color);
      circle.path.setAttribute('stroke-width', state.width);
  
      var value = Math.round(circle.value() * 100);
      if (value === 0) {
        circle.setText('');
      } else {
        circle.setText(value);
      }
  
    }
  });
  bar.text.style.fontFamily = '"Raleway", Helvetica, sans-serif';
  bar.text.style.fontSize = '2rem';
  
  bar.animate(1.0);  // Number from 0.0 to 1.0

html file:

<div id="container"></div>

settings.py:

STATIC_URL = '/static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]

I'm getting correct output in command prompt but it is not displaying on template.

output in cmd:

"GET /static/js/script.js HTTP/1.1" 304 0
4
  • where is the script tag in your HTML? Commented Jun 30, 2022 at 4:41
  • i have not added here Commented Jun 30, 2022 at 4:47
  • did you have {% load static %} tag in your base template file Commented Jun 30, 2022 at 6:08
  • yes i added that also Commented Jun 30, 2022 at 6:29

1 Answer 1

3

Then add script in your html as:

<script type="text/javascript" src="{% static 'js/script.js' %}"></script>
Sign up to request clarification or add additional context in comments.

4 Comments

i mean i have not added here but added in my project
whenever you ask anything always provide the complete code so we can help you better.
<script src="{% static '/js/dist/progressbar.min.js' %}"></script> Now i have added this also but not displayed on template
edit your question and show me your html where you added and settings.py also.

Your Answer

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