0

我正在使用 Ubuntu 和Django 1.3.7. 以下是各种相关设置:

我的目录结构:

mysite/
      manage.py
      settings.py
      __init__.py
      urls.py
      myapp/
          __init__.py
          forms.py
          models.py
          views.py
          templates/
               index.html
               home.html
      static/
           common.css
           ...
           ...

我的settings.py文件:

import os.path
SETTINGS_ROOT = os.path.dirname(__file__)
INSTALLED_APPS = (
    ...
    ...
       'django.contrib.staticfiles'
    )
    STATIC_ROOT = os.path.join(SETTINGS_ROOT, "static/")
    STATIC_URL = '/static/'

在我的模板html文件中:

<link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap.css">

尽管如此,这些页面仍然没有显示任何图像、css 或 js 文件。我已经阅读了文档。但没有任何帮助。为了使文件运行,我还需要包含/修改什么?

4

3 回答 3

0
STATICFILES_DIRS = (
    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
    '/path/to/your/project/assets',
)
于 2013-03-12T18:23:17.627 回答
0

我的静态文件配置如下。

PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
enter code herePER_DIR = os.path.abspath(os.path.join(PROJECT_DIR, os.path.pardir))
STATIC_ROOT = os.path.join(SUPER_DIR, 'static')
STATIC_URL = '/static/'

它可能会有所帮助

于 2013-04-26T09:21:09.147 回答
0

设置.py

import os
SETTINGS_ROOT = os.path.dirname(__file__)

STATIC_ROOT = os.path.join(SETTINGS_ROOT, "static")
STATIC_URL = '/static/'

STATICFILES_DIRS = (

    os.path.join(SETTINGS_ROOT, 'static'),
)

主要网址.py

from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

admin.autodiscover()

urlpatterns = patterns('',
    ................
) 

urlpatterns += staticfiles_urlpatterns()

模板

<link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap.css">
于 2013-03-13T02:16:37.190 回答