我尝试了几种设置组合,但无法在我的模板中加载我的javascript文件。当我尝试在Pycharm中调试我的代码时,它会给出一个错误,说它正试图在我的“templates”文件夹中找到我的静态文件。'
来自settings.py
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "templates")],
'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_FINDERS = ('django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder')
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static")),
STATIC_ROOT = (os.path.join(os.path.dirname(BASE_DIR), "static"))
项目/模板/ index.html中:
{% load staticfiles %}
<!DOCTYPE html>
<html>
<head>
<title>React Flux</title>
<script src="{% static 'js/fb.me/react-0.13.3.js'%}"></script>
<script src="https://fb.me/JSXTransformer-0.13.3.js"></script>
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script
</head>
<body>
<div id="component"></div>
<script type="text/jsx">
var HelloWorld = React.createClass({
render: function() {
return <div>Hello World!!</div>;
}
});
React.render(<HelloWorld />, document.getElementById('component'));
</script>
我的错误:
获取http://localhost:63342/Project/templates/%7B%%20static%20'js / fb.me / react-0.13.3.js'%% 7D 404(未找到)
导致此错误的原因是什么? 为什么要在模板文件夹中查找我的静态文件?
编辑:
urls.py
urlpatterns = patterns('',
url(r'^$', 'Core.views.home' , name='home'),)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)