简体   繁体   中英

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

I want to connect my .html to .js . 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.

在此处输入图片说明

Here's map.html :

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

</head>
<body>

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

Here's map.js :

document.write("testing");

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

Here's views.py :

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

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:

mysite/personal/static/personal/js/map.js

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM