Index.h
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" href="http://stackoverflow.com/static/icons/tabIcon.svg" />
<link rel="stylesheet" href="http://stackoverflow.com/static/posty.css" />
<meta http-equiv="content-security-policy" content="" />
<link
rel="modulepreload"
href="http://stackoverflow.com/static/_app/immutable/start-6f351e07.js"
/>
<link
rel="modulepreload"
href="http://stackoverflow.com/static/_app/immutable/chunks/index-d9a79891.js"
/>
<link
rel="modulepreload"
href="http://stackoverflow.com/static/_app/immutable/chunks/index-d827f58a.js"
/>
<link
rel="modulepreload"
href="http://stackoverflow.com/static/_app/immutable/chunks/singletons-eca981c1.js"
/>
</head>
<body>
<div>
<script type="module" data-sveltekit-hydrate="45h" crossorigin>
import {
set_public_env,
start,
} from "/static/_app/immutable/start-6f351e07.js";
set_public_env({});
start({
target: document.querySelector('[data-sveltekit-hydrate="45h"]')
.parentNode,
paths: { base: "", assets: "/static/" },
session: {},
route: true,
spa: true,
trailing_slash: "never",
hydrate: null,
});
</script>
</div>
</body>
</html>
svelte.config.js
import adapter from '@sveltejs/adapter-static';
import preprocess from 'svelte-preprocess';
/** @type {import('@sveltejs/kit').Config} */
const config = {
preprocess: preprocess(),
kit: {
adapter: adapter({
assets: 'build/assets',
out: 'dist',
fallback: 'index.html',
precompress: false
})
}
};
export default config;
paramètres.py
# ...
DEBUG = True
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'build/assets')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'build')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
# ...
Erreurs
The resource from “http://127.0.0.1:8000/_app/immutable/pages/__layout.svelte-bd484656.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
The resource from “http://127.0.0.1:8000/_app/immutable/assets/__layout-ce6f71c3.css” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
The resource from “http://127.0.0.1:8000/_app/immutable/chunks/index-d9a79891.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff).
... 9+ more errors
Desc
Même en utilisant python manage.py runserver --nostatic --insecure
(en utilisant whitenoise) provoque toujours cette erreur, et après avoir construit la version de production, je dois changer toutes les urls dans le fichier index.html
pour commencer /static/
ou bien aucun fichier ne serait trouvé, y a-t-il un moyen de corriger ou d'automatiser pendant le déploiement, et y a-t-il une meilleure façon de faire cela ? Merci !