1

我无法通过第一步,设置它。

这是我的应用程序的settings.py:

MEDIA_URL = '/media/'
MEDIA_ROOT = '/home/django/ristoturisto/media'
FILEBROWSER_DIRECTORY = ''
STATIC_ROOT = '/home/django/ristoturisto/static'
STATIC_URL = '/static/'
FILEBROWSER_DIRECTORY = MEDIA_ROOT

文件夹存在,我从 pwd 复制了名称。

我确实收集了静电,这很有效。

但是当我这样做时:

python manage.py 测试文件浏览器

我收到以下错误:

Creating Test for the FileBrowser site: filebrowser
Creating test database for alias 'default'...
...........F......ERemoving left-over tmp dir: /home/django/ristoturisto/media/tmp_test_0

======================================================================
ERROR: runTest (filebrowser.tests.sites.TestSite_filebrowser)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/filebrowser/tests/sites.py", line 236, in runTest
    test_do_upload(self)
  File "/usr/lib/python2.6/site-packages/filebrowser/tests/sites.py", line 99, in test_do_upload
    response = test.c.post(url, data=f.read(), content_type='application/octet-stream', HTTP_X_REQUESTED_WITH='XMLHttpRequest', X_File_Name='testimage.jpg')
  File "/usr/lib/python2.6/site-packages/django/test/client.py", line 449, in post
    response = super(Client, self).post(path, data=data, content_type=content_type, **extra)
  File "/usr/lib/python2.6/site-packages/django/test/client.py", line 262, in post
    return self.request(**r)
  File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/usr/lib/python2.6/site-packages/django/contrib/admin/views/decorators.py", line 16, in _checklogin
    return view_func(request, *args, **kwargs)
  File "/usr/lib/python2.6/site-packages/django/views/decorators/csrf.py", line 77, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/filebrowser/sites.py", line 476, in _upload_file
    file_already_exists = self.storage.exists(file_name)
  File "/usr/lib/python2.6/site-packages/django/core/files/storage.py", line 230, in exists
    return os.path.exists(self.path(name))
  File "/usr/lib/python2.6/site-packages/django/core/files/storage.py", line 246, in path
    raise SuspiciousOperation("Attempted access to '%s' denied." % name)
SuspiciousOperation: Attempted access to '/tmp_test_0/testimage.jpg' denied.

======================================================================
FAIL: test_directory (filebrowser.tests.settings.SettingsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/filebrowser/tests/settings.py", line 31, in test_directory
    self.assertEqual(os.path.basename(DIRECTORY), '')
AssertionError: 'media' != ''

----------------------------------------------------------------------
Ran 19 tests in 3.810s

FAILED (failures=1, errors=1)
Destroying test database for alias 'default'...
4

1 回答 1

1

变量MEDIA_ROOT末尾必须有斜杠。

来自django-filebrowser设置文件的注释和下面一行

# DO NOT USE A SLASH AT THE BEGINNING, DO NOT FORGET THE TRAILING SLASH AT THE END.
DIRECTORY = getattr(settings, "FILEBROWSER_DIRECTORY", 'uploads/')

设置测试脚本失败的两行

# Check for trailing slash
self.assertEqual(os.path.basename(DIRECTORY), '')
于 2013-09-14T20:34:41.033 回答