В основном, запрос Django GET не может найти путь к моему файлу.
Я прочитал все остальные вопросы, такие как: как загрузить изображение с помощью phaser , но я до сих пор не могуесть ответ. Вот структура файлов:
project-> app-> static-> .js и .html файлы
project-> app-> static-> assets-> .png файл
HTML:
home.html
{% load static %}
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head>
<title>Dice Game</title>
<link rel="stylesheet" href="{% static 'home.css' %}" type="text/css">
<script type="text/javascript" src='{% static "phaser.js" %}'></script>
<script type="module" src='{% static "dice_game.js" %}'></script>
</head>
<body>
<div id="dice-game"></div>
<div class="game_box">
<h1>Hello</h1>
</div>
<p>{{request.user}}</p>
</body>
</html>
JS:
dice_game.js
import {Dice, Dice_Roll} from './dice.js';
var new_die = new Dice(2);
var config = {
type:Phaser.AUTO,
parent:'dice-game', // populates the div tag class in the html
width:800,
height:600,
physics: {
default:'arcade',
},
scene: [Dice_Roll]
}
var game = new Phaser.Game(config);
dice.js
export class Dice{
constructor(num) {
this.num = num;
this.state = true;
}
}
export class Dice_Roll extends Phaser.Scene {
constructor() {
super({key:"Dice_Roll"});
}
preload() {
this.load.image('die', "assets/blank_die.png");
}
create() {
this.add.image(400, 300, 'die');
}
}
PYTHON:
urls.py
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static
from django.urls import path
from pages.views import home_view, about_view
from products.views import product_detail_view, product_create_view
urlpatterns = [
path('admin/', admin.site.urls),
path('', home_view, name='home'),
path('about/', about_view, name='about_view'),
path('product/', product_detail_view, name='product_detail'),
path('create/', product_create_view, name='product_create'),
]
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
app.views.py
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def home_view(request, *args, **kwargs):
return render(request, "app/home.html", {})
phaser.js:94680 GET http://127.0.0.1:8000/assets/blank_die.png 404 (Not Found)