javascript - 在 Django 中使用 gltf 加载器加载三个 JS 模型
问题描述
我正在尝试在本地环境的 Django(3.0.3) 应用程序中加载三个 JS 模型。
模板:
<script>
var address_to_model ="{% static 'models/matilda/scene.gltf' %}"; // Pass this variable to .js file
</script>
<script src="{% static 'js/matilda.js' %}"></script>
matilda.js:
var loader = new THREE.GLTFLoader( );
loader.load( address_to_model, function ( gltf ) {
scene.add( gltf.scene );
}, undefined, function ( error ) {
console.error( error );
} );
renderer.outputEncoding = THREE.sRGBEncoding;
页面加载时没有任何 Django 错误,它显示 ThreeJS 窗口正在工作,但模型未加载,在 Chrome 错误控制台中,我收到此错误:
获取http://127.0.0.1:8000/matilda/models/matilda/scene.gltf 404(未找到)
我认为它不应该检查这个 URL,因为我没有在 urls.py 中解析它,并且这个地址中没有任何内容。它应该使用collectstatic命令加载在“static/models/matilada”中收集的模型。
我检查了这些链接,但它们没有帮助: * javascript 文件中的 Django {% static 'path' %} *从外部 javascript 正确访问 django 静态文件 * Django:使用框架的外部 JS 不加载 * https://pypi. org/project/django-js-urls/
解决方案
您需要在 IP 地址上托管网站,以便加载 threejs gltf 模型。
推荐阅读
- c - Bison - 符号表 - malloc 的免费匹配
- sql - 使用分组集 - 识别级别名称并消除某些集
- asp.net - 如何将 RadTextBox 名称属性设置为静态以在 Javascript 中使用
- r - 如何收集每 4 列,但变量可能有不同的长度
- c# - 将 Access-Control-Request-Headers 设置为 * 有哪些安全风险?
- batch-file - 如何控制变量检索哪个成员值
- mariadb - 加载字段后的时间戳问题为 0000-00-00 00:00:00
- javascript - 如何在 javascript/jquery 中更改 iframe 高度?
- excel - 是否可以清除我的工作簿中单元格的特定填充颜色
- c - 删除数据库时如何处理 C 中的 sqlite3_exec 错误?