我的 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
-行政/
-css/
-图片/
-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" />
我的 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,我非常感谢您的项目布局,我在下面链接的问题中投票支持您的答案。