Django Integration vue appears "Uncaught SyntaxError: Unexpected token <"

problem description

when trying to integrate vue with django, django was able to find the relevant static file, but reported an error "Uncaught SyntaxError: Unexpected token <" .
clipboard.png

clipboard.png
preview
clipboard.png

dist

distserve5000

clipboard.png

vue-cli 3.0vuebudildist

clipboard.png

django

clipboard.png

related codes

setting.py configuration

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": ["dist"],
        "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",
            ],
        },
    },
]
STATICFILES_DIRS = [
    os.path.join(BASE_DIR, "dist")
]

urls.py configuration

urlpatterns = [
    path("admin/", admin.site.urls),
    re_path(r"", TemplateView.as_view(template_name="index.html"))
]

ask the boss for help!

Oct.19,2021

check whether you returned JavaScript or JSON?. Most likely, HTML/XML was returned and could not be parsed.
did you write something like this

<script src="index.html"></script>

reference:
Uncaught SyntaxError: Unexpected token

Menu