我是Django的新手,對此非常困惑。Django 1.5不會在開發中獲取靜態文件
以下是有關部分在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/')
我的項目文件的結構是這樣的:
{% 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>
但:
MyProj
manage.py
MyProj
settings.py
urls.py
templates
base.html
static
css
js
在base.html文件開頭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 docs並嘗試了幾種替代設置,但沒有一個能夠幫助解決問題。所以感謝你的提示。
url.spy
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')),
)
難道您發佈urls.py ? DEBUG設置爲True嗎? – esauro
已添加urls.py。是的,DEBUG被設置爲True。 – supermario