hop38 hop38 - 2 years ago 114
HTML Question

Why won't my .html file connect to .js file?

I want to connect my

. I'm trying to run this simple program but it's not working. Below is the screenshot of my file path and files I'm working with.

enter image description here


<!DOCTYPE html>
<html lang="en">


<script type="javascript" src="map.js"></script>



The problem is below. How can I render the
file along with the


def map(request):
return render(request, 'personal/map.html')

Answer Source

A common CMS convention is to save JavaScript files in a static folder. You save anything that you don't want your template engine messing with there: images, javascript, css, etc.

It looks like you may need to save map.js at this path:


After that, you'll need to update you script link in your HTML to something like:

<script src="static/js/map.js">

The src path here isn't relative to where you store the file on your computer, but to the URI that your web server associates with it. Depending on how you've set things up, you'll need some portion of the new path. Django has a few ways of linking to static resources, but I'm not familiar enough with the platform to tell you which option you should use.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download