2

I need to inculde my JavaScript file in django. I know how to include CSS files. I'm doing it this way:

<link rel="stylesheet" href="{% static 'demo/style.css' %}"/>

How can I include my JavaScript file?

2 Answers 2

7

There are two ways to do this (inline scripts and external scripts):

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test page</title>
  </head>
  <body>
    Inline script (option 1):
    <script>
      // your js code here
    </script>
    External script (option 2):
    <script src="your-code-file.js"></script>
  </body>
</html>

You are probably interested in this one:

<script src="your-code-file.js"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

I resolved it. Thank you. <script src="/static/demo/js/demo.js"></script
4

I know how to include files of CSS. […] How can I include my javascript file?

One obvious answer is “Manage it the same way as other static files. Then include it with a script element, the same way you'd do any JavaScript file”.

If you've tried that, or other things, please edit your question to say what you tried and what happened instead.

Comments

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.