我跟着tutorial用Apache和mod_wsgi(在Windows上)设置Django,但每当我尝试访问静态文件时,我都会收到以下错误: /static/js/map.js中的TypeError 对象类型' NoneType'没有len()
这与document_root有关:
C:\Python27\lib\site-packages\django\core\handlers\base.py in get_response
TypeError("object of type 'NoneType' has no len()",)
resolver_match (func=<function serve at 0x0A4FEF70>, args=(), kwargs={'path': u'js/map.js', 'document_root': None}, url_name='django.views.static.serve', app_name='None', namespace='')
为什么会发生这种情况,我需要在哪里设置&#39; document_root&#39;?
更多信息:
Exception Location: C:\Python27\Lib\ntpath.py in splitdrive, line 114
Python Executable: C:\xampp\apache\bin\httpd.exe
Python Version: 2.7.8
C:\Python27\Lib\ntpath.py in join
result_drive, result_path = splitdrive(path) ...
▼ Local vars
Variable Value
paths (u'js/map.js',)
path None
答案 0 :(得分:0)
我想通了,这不是Django错误,只是我对Apache配置感到愚蠢(一如既往):
# NOTE: Where filenames are specified, you must use forward slashes
# instead of backslashes (e.g., "c:/apache" instead of "c:\apache").
# If a drive letter is omitted, the drive on which httpd.exe is located
# will be used by default. It is recommended that you always supply
# an explicit drive letter in absolute paths to avoid confusion.
我有一个像这样的别名:
Alias /static/ C:\path\static\
应该是
Alias /static/ C:/path/static/
这很奇怪,因为使用反斜杠的WSGIScriptAlias指令有效。