我试图在python flask项目中显示一个javascript文件。我在调用javascript文件的html文件中使用块。它只是没有显示在网页上
如果我删除了项目的base.html部分,并将所有内容都放到snake.html文件中,它运行良好,这对我来说Javascript很好,我只是误解了Flask部分
如果您能给我任何帮助,我将不胜感激
基本.html
<html>
<head>
{% if title %}
<title>{{ title }}</title>
{% else %}
<title>Unseen Arcade</title>
{% endif %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style> body {padding: 10; margin: 10;} </style>
<script src="p5.min.js"></script>
<script src="addons/p5.dom.min.js"></script>
<script src="addons/p5.sound.min.js"></script>
{% block scripts %}{% endblock scripts %}
</head>
<body>
<div>Unseen Arcade: <a href="/index">Home</a></div>
<hr>
{% block content %}{% endblock content %}
</body>
</html>
蛇.html
{% extends "base.html" %}
{% block scripts %}
<script src="{{url_for('static', filename='snake/snake.js')}}"></script>
{% endblock %}
{% block content %}
<body>
<h2> Snake Game:</h2>
<p>Use the keys W, A, S, and D to control the direction of the snake, if you get onto the leaderboard with a score above 50 you will receive a hint on the locations of other secret arcades in London.$
</body>
{% endblock %}
文件夹布局:
FlaskApp/
FlaskApp/
forms.py
__init__.py
routes.py
static/
p5.min.js
addons/
p5.dom.min.js
p5.sound.min.js
snake/
snake.js
templates/
base.html
snake/
snake.html
flaskapp.wsgi
感谢Kstullich,我发现我在base.html中使用的路径不正确,并将脚本路径替换为使用url\u。也没有考虑在浏览器中查看js控制台
相关问题 更多 >
编程相关推荐