Django imports external js error: Uncaught SyntaxError: Unexpected token '<'

Solution:

  1. Import using CDN, such as importing bootstrap global css files.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
  1. Import local files using template syntax, such as importing jqury.

{% load static %}
<script src="{% static 'js/jquery.js' %}"></script>

Static needs to be configured in the setting file before importing

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

Guess you like

Origin blog.csdn.net/weixin_57742734/article/details/129596203