English 中文(简体)
Django 1.4:静态档案
原标题:Django 1.4 : static file not found
  • 时间:2012-04-16 19:38:18
  •  标签:
  • django

我试图回避,但我可以确定我的问题。 许多人面临这一问题,并试图遵循他们的指示,但我仍然可以这样做。 因此,我的组合存在任何问题?

--环境

PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(PROJECT_PATH,  static )
STATIC_URL =  /static/ 

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.core.context_processors.tz",
"django.contrib.messages.context_processors.messages")

- 概 况

render_to_response( authen/login.html ,context_instance=RequestContext(request))

--——————

<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}styles/reset.css" />
<link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}styles/root.css" />

--

[16/Apr/2012 21:27:26] "GET /authen/login.php HTTP/1.1" 200 1391
[16/Apr/2012 21:27:26] "GET /static/styles/reset.css HTTP/1.1" 404 1652
[16/Apr/2012 21:27:26] "GET /static/styles/root.css HTTP/1.1" 404 1649 

页: 1

if settings.DEBUG:
    urlpatterns += patterns( django.contrib.staticfiles.views ,
        url(r ^static/(?P<path>.*)$ ,  serve ),
    )
最佳回答

你们或许会想:

https://docs.djangoproject.com/en/1.4/ref/contrib/staticfiles/#static-file-development-view

最新资料:我看到你在静态档案方面有旋律。 你们是否在环境中有DEBUG=True。 ??

问题回答

I had the same problem, it couldnt find any static file. But With Sophy SEMs comment (see above) it worked:

Instead of setting

STATIC_ROOT = os.path.join(SITE_ROOT,  static )

I ve set

STATIC_ROOT =   
STATICFILES_DIRS = ( os.path.join(SITE_ROOT,  static ), )

Then, it worked. First I could nt believe it makes any difference, but as I ve retestet again, it is significant.





相关问题
How to get two random records with Django

How do I get two distinct random records using Django? I ve seen questions about how to get one but I need to get two random records and they must differ.

Moving (very old) Zope/Plone Site to Django

I am ask to move data from a (now offline) site driven by Plone to a new Django site. These are the version informations I have: Zope Version (unreleased version, python 2.1.3 ) Python Version 2.1....

Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

Flexible pagination in Django

I d like to implement pagination such that I can allow the user to choose the number of records per page such as 10, 25, 50 etc. How should I go about this? Is there an app I can add onto my project ...

is it convenient to urlencode all next parameters? - django

While writing code, it is pretty common to request a page with an appended "next" query string argument. For instance, in the following template code next points back to the page the user is on: &...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

热门标签