【发布时间】:2016-04-06 06:21:12
【问题描述】:
我使用 Django-rest-framework 编写了一个 rest-API,并以 angularjs 应用程序作为前端。我还在使用 gulp 构建我的 angularjs 应用程序的压缩版本,并将其输出到我的 django 应用程序的静态文件目录中。我尝试使用 django 模板视图,但这会导致控制台错误:
vendor-001932f856.js:1 Uncaught SyntaxError: Unexpected token <
app-2d5e1cec88.js:1 Uncaught SyntaxError: Unexpected token <
这 2 个文件都是有效的 javascript 文件。这是我的网址文件:
from django.views.generic import TemplateView
urlpatterns = [
url(r'^.*$',TemplateView.as_view(template_name="index.html")),
]
这些是我的静态文件和模板设置:
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, 'static/eventshop'),
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'static/eventshop')],
'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',
],
},
},
]
我的 Angular 应用程序位于 static/eventshop 中,并且 index.html 中的链接是相对 url(因此没有 STATIC_URL 前缀)。
为什么它给我这个错误和/或在 django 中提供“静态”角度应用程序的最佳方式是什么?
【问题讨论】:
-
看起来更像是 JS 错误而不是 django 错误。如果它是未缩小的,它是否有效?
标签: javascript python angularjs django static