我是 Django 的新手,对此我感到非常困惑。
以下是 settings.py 中的相关部分:
import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
STATIC_URL = 'http://http://127.0.0.1:8000/static/'
STATICFILES_DIRS = (
PROJECT_ROOT+'/static/')
TEMPLATE_DIRS = (
PROJECT_ROOT + '/templates/')
我的项目文件结构是这样的:
MyProj
manage.py
MyProj
settings.py
urls.py
templates
base.html
static
css
js
在 base.html 中以:
{% load staticfiles %}
{% load i18n %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<link rel="shortcut icon" href="http://twitter.github.com/bootstrap/assets/ico/favicon.ico">
<link href="{{ STATIC_URL }}css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<link href="{{ STATIC_URL }}css/bootstrap-responsive.min.css" rel="stylesheet">
</head>
<body>
但是 django 没有得到任何静态文件:
[15/Oct/2013 05:36:06] "GET /accounts/login/ HTTP/1.1" 200 3402
[15/Oct/2013 05:36:06] "GET /static/css/bootstrap.min.css HTTP/1.1" 404 2089
[15/Oct/2013 05:36:06] "GET /static/css/bootstrap-responsive.min.css HTTP/1.1" 404 2122
[15/Oct/2013 05:36:06] "GET /static/js/jquery.min.js HTTP/1.1" 404 2074
[15/Oct/2013 05:36:06] "GET /static/js/prettify.js HTTP/1.1" 404 2068
[15/Oct/2013 05:36:06] "GET /static/js/bootstrap.min.js HTTP/1.1" 404 2083
[15/Oct/2013 05:36:06] "GET /static/css/bootstrap.min.css HTTP/1.1" 404 2089
[15/Oct/2013 05:36:06] "GET /accounts/login/ HTTP/1.1" 200 3402
[15/Oct/2013 05:36:06] "GET /static/css/bootstrap-responsive.min.css HTTP/1.1" 404 2122
[15/Oct/2013 05:36:19] "GET /static/css/bootstrap.min.css HTTP/1.1" 404 2089
[15/Oct/2013 05:36:20] "GET /static/css/bootstrap.min.css HTTP/1.1" 404 2089
我阅读了 Django文档并尝试了几种替代设置,但没有一个有助于解决问题。所以感谢你的提示。
网址间谍
from django.conf.urls import patterns, include, url
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
# Examples:
#url(r'^$', 'myproj.views.home', name='home'),
# url(r'^myproj/', include('myproj.foo.urls')),
# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
url (r'^accounts/', include('registration.backends.default.urls')),
)