Django / Static文件或图像未正确加载

时间:2015-05-04 19:03:30

标签: python django django-staticfiles django-static

如果错误已经发布,我很抱歉,但我无法解决这个问题。我有以下django项目结构。

.
├── db.sqlite3
├── manage.py
├── rango
│   ├── admin.py
│   ├── __init__.py
│   ├── migrations
│   │   ├── __init__.py
│   ├── models.py
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── static
│   ├── duck.jpg
│   └── images
│       └── duck.jpg
├── tango
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   ├── wsgi.py
└── templates
    └── rango
        └── index.html

settings.py中的INSTALLED_APPS和STATIC FILE设置如下。

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rango',
)  

STATIC_PATH = os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'

STATICFILES_DIR = (
    STATIC_PATH,
)

<!DOCTYPE html>
{% load staticfiles %}
<html>
    <head>
        <title>Rango</title>
    </head>

    <body>
        <h1> Rango says...</h1>
        hello <strong>{{ boldmessage }}</strong><br/>
        <img src="{% static "duck.jpg" %}" alt="Picture of Duck" /><br/>       
        <a href="/rango/about">About</a><br/>

    </body>
</html>

# File: urls.py

from django.conf.urls import patterns, url
from rango import views
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = patterns('',
    url(r'^$',views.index,name='index'),
    url(r'^about',views.about,name='about'),
)

urlpatterns += staticfiles_urlpatterns()

我不确定为什么它不起作用。

- 编辑 - 我不确定发生了什么,但是在进行了以下更改之后,这看起来基本上和我一样

STATIC_PATH = os.path.join(BASE_DIR,'static')
print os.path.join(BASE_DIR,'static')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    STATIC_PATH,
)

感谢您的帮助!!

0 个答案:

没有答案