#javascript #django #postgresql #bootstrap-4 #jinja2
#javascript #django #postgresql #bootstrap-4 #jinja2
Вопрос:
base.html файл Здесь используется jinja, и все js связаны, я создал частичный файл навигации и нижнего колонтитула, и проблема заключается в части навигации
{% load static %}
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="" />
<meta name="author" content="" />
<title>Home</title>
<!-- Favicon-->
<link rel="icon" type="image/x-icon" href="{% static 'assets/img/favicon.ico'%}" />
<!-- Font Awesome icons (free version)-->
<script src="https://use.fontawesome.com/releases/v5.13.0/js/all.js" crossorigin="anonymous"></script>
<!-- Google fonts-->
<link href="{% static 'https://fonts.googleapis.com/css?family=Merriweather Sans:400,700'%}" rel="stylesheet" />
<link href="{% static 'https://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic'%}" rel="stylesheet" type="text/css" />
<!-- Third party plugin CSS-->
<link href="{% static 'https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css'%}" rel="stylesheet" />
<!-- Core theme CSS (includes Bootstrap)-->
<link href="{% static 'css/styles.css'%}" rel="stylesheet" />
</head>
<body id="page-top">
<!-- Navigation-->
{% include 'partials/_navigation.html' %}
<!-- Navigation-->
<!--content-->
{% block content %}
{% endblock %}
<!--content-->
<!-- Footer-->
{% include 'partials/_footer.html' %}
<!-- Footer-->
<!-- Bootstrap core JS-->
<script src="{% static 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js'%}"></script>
<script src="{% static 'https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.bundle.min.js'%}"></script>
<!-- Third party plugin JS-->
<script src="{% static 'https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js'%}"></script>
<script src="{% static 'https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js'%}"></script>
<!-- Core theme JS-->
<script src="{% static 'js/scripts.js'%}"></script>
</body>
</html>
Настройки:
Это часть настроек, указывающая статический путь
STATIC_URL = ‘/static/’
#Manually Done
STATICFILES_LOCATION = 'static'
STATIC_URL='/static/'
STATIC_ROOT= os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'MyProject/static')
]
Ответ №1:
Когда у вас есть URL-адрес файла js, вам не нужен jinja.
Вместо:
<script src="{% static 'https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js'%}"></script>
Использовать:
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
и т.д…