我正在尝试从myapp / static / myapp / css加载Django中的css文件,但我无法让它工作。 Chrome控制台表示无法获取文件(404)。
Settings.py:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_DIR = os.path.dirname(__file__)
...
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
)
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_ROOT = ''
STATIC_URL = '/static/'
urls.py:
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^projects/', include('projects.urls', namespace='projects')),
url(r'^home/', include('home.urls', namespace='home')),
)+static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
home urls.py:
from django.conf.urls import patterns,url
from projects.views import DetailView, ListView
urlpatterns = patterns('',
url(r'^(?P<pk>\d+)/$', DetailView.as_view(), name='detail'),
url(r'^$', ListView.as_view(), name='list'),
)
base.html文件:
<link href="{% static 'home/css/bootstrap.min.css' %}" rel="stylesheet" media="screen">
<script src="{% static 'home/js/jquery-2.1.1.min.js' %}" type="text/javascript"></script>
答案 0 :(得分:4)
我发现代码运行得非常好。问题是我忘了把家庭应用程序放在INSTALLED_APPS中。
感谢您的时间。