1

我正在尝试加载 CSS 文件,但由于某种原因它无法找到该文件。这是我在加载文件时遇到的错误:

---[05/May/2013 11:31:58] "GET /static/css.css HTTP/1.1" 404 1625

File structure


Folder structure
      ecomstore
          ecomstore
                 catalog
                 preview
                     Templates
                        Catalog
                        base.html
          static
              css.css

网址.py

from django.contrib import admin
import os
admin.autodiscover()

static = os.path.join(os.path.dirname(__file__), 'static')
print 'static=',static

urlpatterns = patterns('',

    (r'^catalog/$','ecomstore.preview.views.home'),
    url(r'^admin/', include(admin.site.urls)),
    (r'^static/(?P<path>.*)$', 'django.views.static.serve',{'document_root':static}),

    (r'^',include('ecomstore.catalog.urls')),
)

base.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "XHTML1-s.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head> 
     <title>DJANGO E-Commerce website</title>
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <title>{% block title %}{% if page_title %}{{ page_title }} - {% endif %} ?     
          {{ site_name }}{% endblock %}</title> 
     <meta name="keywords" content="{{ meta_keywords }}" /> 
     <meta name="description" content="{{ meta_description }}" />

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

    <script src="/static/jquery.js" type="text/javascript"></script>
</head> 
<body> 
    {% block site_wrapper %}{% endblock %} 
</body>
</html>

settings.py

STATIC_ROOT = ''

STATIC_URL = '/static/'
4

2 回答 2

0

File structure should be like so :

.
├── {app_name_1}
│   ├── ...
└── {app_name_2}
    ├── static
    │   └── {app_name_2}  # Put static files in this folder
    │       ├── css
    │       ├── img
    │       └── js
    └── templates
        └── {app_name_2}  # Put templates in this folder
于 2013-05-05T17:30:48.863 回答
0

从 urls.py 中删除这一行,因为它在开发中不需要:

(r'^static/(?P<path>.*)$', 'django.views.static.serve',{'document_root':static}),

它应该被修复。

于 2013-05-05T17:21:35.257 回答