Django 文件浏览器扩展配置错误
我应该将文件浏览器的扩展名设置放在哪里。
我将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否已将第一个代码块放入主 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!
如果您尝试单独执行 django 模块之一,则会出现这种错误。只需将您的应用程序添加到 settings.INSTALLED_APPLICATIONS 中就足够了。
或者我认为您可能正在尝试导入错误的设置文件,
尝试
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