我的settings.py是这样的:
import os
ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), '..'))
STATIC_ROOT = ''
STATIC_URL = '/static/waijiaocrm/'
STATICFILES_DIRS = (
os.path.join(ROOT, '/static/waijiaocrm/')
)
我的静态文件存储在project / static / waijiaocrm /
中静态/ waijiaocrm
-admin /
-css /
-image /
-js /
我的模板是这样的:
{% load static from staticfiles %}
<link href="{% static 'css/base.css' %}" rel="stylesheet" type="text/css" />
<link href="{% static 'css/login.css' %}" rel="stylesheet" type="text/css" />
my urls.py:
url(r'^login/$', 'django.contrib.auth.views.login',
{'authentication_form': MyAuthenticationForm,
'template_name': 'waijiaocrm/login.html'}, name="login"),
当我运行登录时,我只能获取登录html,没有css或图像文件,我按照文档说的那样做了,但无法获得正确的页面,如何解决这个问题?
[08/May/2013 17:54:10] "GET /accounts/login/ HTTP/1.1" 200 2814
[08/May/2013 17:54:10] "GET /static/waijiaocrm/css/base.css HTTP/1.1" 404 1662
[08/May/2013 17:54:10] "GET /static/waijiaocrm/css/login.css HTTP/1.1" 404 1665
[08/May/2013 17:54:10] "GET /static/waijiaocrm/js/lib/jquery-1.8.2.min.js HTTP/1.1" 404 1704
[08/May/2013 17:54:10] "GET /accounts/login/image/crm_logo.png HTTP/1.1" 404 3778
[08/May/2013 17:54:10] "GET /static/waijiaocrm/js/lib/jquery.placeholder.min.js HTTP/1.1" 404 1722
[08/May/2013 17:54:10] "GET /static/waijiaocrm/js/formValidator.js HTTP/1.1" 404 1683
[08/May/2013 17:54:10] "GET /static/waijiaocrm/js/login.js HTTP/1.1" 404 1659
[08/May/2013 17:54:10] "GET /static/waijiaocrm/js/lib/jquery.placeholder.min.js HTTP/1.1" 404 1722
[08/May/2013 17:54:10] "GET /static/waijiaocrm/js/formValidator.js HTTP/1.1" 404 1683
[08/May/2013 17:54:10] "GET /static/waijiaocrm/js/login.js HTTP/1.1" 404 1659
我终于修复了它,这是因为template_dir配置错误,感谢所有人的耐心和时间,@ Hedde,我非常感谢你的项目布局,我在你的问题中投票给你答案链接如下。
答案 0 :(得分:0)
假设waijiaocrm
是一个应用,您应该使用该前缀
{% static 'waijiaocrm/css/base.css' %}
答案 1 :(得分:0)
如果您的MEDIA_URL定义为'/ media /',您可以通过将以下代码段添加到您的urls.py来实现此目的
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
# ... the rest of your URLconf goes here ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
答案 2 :(得分:0)
确保您的主应用程序,其中包含wsgi.py的应用程序已在已安装的应用程序中列出。
答案 3 :(得分:0)
我必须使用
STATICFILES_DIRS = ( '/home/USERNAME/webapps/django/PROJECT/static/', )
这帮助了我。