2

我在我认为是一个非常简单的问题上遇到了很多麻烦,但我就是想不通。现在我的目录结构如下所示:

.
├── css
│   └── registration.css
├── images
│   └── icon.png
├── __init__.py
├── manage.py
├── registration
│   ├── __init__.py
│   ├── templates
│   │   └── loading_page.html
│   ├── views.py
├── settings.py
├── static
│   ├── css
│   │   └── registration.css
│   └── images
│       └── icon.png
├── test.txt
└── urls.py

我只定义了一个根 url,但这是文件:

from django.conf.urls.defaults import patterns, include, url
import registration

urlpatterns = patterns(
    '',
    url(r'^$', 'registration.views.registration', name="registration")
)

我的设置和模板的相关行如下:

<link rel="stylesheet" type="style/css" href= "{{ STATIC_URL }}css/registration.css">

STATIC_ROOT = os.getcwd()
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.getcwd(),
)

基本上,当我尝试链接到如上所示的静态文件时,我得到 404。我想我可以为静态文件制作 url 模式,但我的理解是静态文件处理程序应该处理这个问题。任何帮助将不胜感激。我意识到有许多类似的问题,但我找不到我认为与问题匹配的东西。

4

3 回答 3

0

how about this

STATICFILES_DIRS = (
    os.path.abspath('./static/')
)
于 2013-07-14T08:06:19.633 回答
0
In your settings.py try it like this:
import os.path
CURRENT_PATH=os.path.abspath(os.path.dirname(__file__).decode('utf-8')).replace('\\','/')   
STATIC_URL ='/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',)
STATICFILES_DIRS = (

os.path.join(os.path.dirname(__file__),'static').replace('\\','/'),

)在您的模板中:取出css目录并直接输入它应该可以工作!

于 2013-07-14T04:46:52.373 回答
0

尝试使用这样的东西

import os
PROYECT = os.path.dirname(os.path.abspath(__file__))

STATIC_ROOT = os.path.join(PROYECT, 'static')



STATICFILES_DIRS = (
    STATIC_ROOT,
)
于 2013-07-14T00:02:59.023 回答