Django 文件浏览器扩展配置错误

发布于 2024-11-02 23:19:37 字数 1166 浏览 1 评论 0原文

我应该将文件浏览器的扩展名设置放在哪里。

我将 filebrowser 扩展配置放入根 settings.py 中:

from django.conf import settings

FILEBROWSER_EXTENSIONS = getattr(settings, "FILEBROWSER_EXTENSIONS", {
    'Image': ['.jpg','.jpeg','.gif','.png','.tif','.tiff'],
    'Document': ['.pdf','.doc','.rtf','.txt','.xls','.csv'],
    'Video': ['.mov','.wmv','.mpeg','.mpg','.avi','.rm'],
    'Audio': ['.mp3','.mp4','.wav','.aiff','.midi','.m4p']
})

当我尝试启动服务器时,出现此错误:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    import settings
  File "/home/kelvin/workspace/exam/settings.py", line 177, in <module>
    'Audio': ['.mp3','.mp4','.wav','.aiff','.midi','.m4p']
  File "/usr/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

Where should I put the extension setting for filebrowser.

I put the filebrowser extension configuration into the root settings.py:

from django.conf import settings

FILEBROWSER_EXTENSIONS = getattr(settings, "FILEBROWSER_EXTENSIONS", {
    'Image': ['.jpg','.jpeg','.gif','.png','.tif','.tiff'],
    'Document': ['.pdf','.doc','.rtf','.txt','.xls','.csv'],
    'Video': ['.mov','.wmv','.mpeg','.mpg','.avi','.rm'],
    'Audio': ['.mp3','.mp4','.wav','.aiff','.midi','.m4p']
})

When i try to start the server, I get this error:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    import settings
  File "/home/kelvin/workspace/exam/settings.py", line 177, in <module>
    'Audio': ['.mp3','.mp4','.wav','.aiff','.midi','.m4p']
  File "/usr/lib/python2.7/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()
  File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
    raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愛放△進行李 2024-11-09 23:19:37

您是否已将第一个代码块放入主 settings.py 中?这是行不通的,因为您实际上是在其内部导入主要设置!

Have you put that first code block inside your main settings.py? That can't work, because you're actually importing the main settings inside itself!

你不是我要的菜∠ 2024-11-09 23:19:37

如果您尝试单独执行 django 模块之一,则会出现这种错误。只需将您的应用程序添加到 settings.INSTALLED_APPLICATIONS 中就足够了。
或者我认为您可能正在尝试导入错误的设置文件,
尝试

import filebrowser.settings

This kind of error appears if you try to exec one of django modules on it's own. Just add your application to settings.INSTALLED_APPLICATIONS and that should be enough.
Alternatively I think maybe you are trying to import wrong settings file,
try

import filebrowser.settings
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文