Mike
Mike

Reputation: 429

How can I include my JavaScript file into an HTML page?

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?

Upvotes: 2

Views: 619

Answers (2)

bignose
bignose

Reputation: 32367

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.

Upvotes: 4

user6269864
user6269864

Reputation:

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>

Upvotes: 7

Related Questions