python – Django CMS – 无法通过cmsplugin_filer_image上传图像

前端之家收集整理的这篇文章主要介绍了python – Django CMS – 无法通过cmsplugin_filer_image上传图像前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个关于 django cms 2.3.3的本地安装的问题:我已经通过pip安装它,在一个单独的virtualenv中.接下来我按照settings.py配置教程,启动了服务器.然后在管理员我创建了一个页面(主页),我试图通过cmsplugin_filer_image在占位符中添加一个图像,但上传似乎不起作用.这是我的settings.py:
  1. # Django settings for cms1 project.
  2. # -*- coding: utf-8 -*-
  3. import os
  4. gettext = lambda s: s
  5. PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
  6.  
  7. DEBUG = True
  8. TEMPLATE_DEBUG = DEBUG
  9.  
  10. ADMINS = (
  11. # ('Your Name','your_email@example.com'),)
  12.  
  13. MANAGERS = ADMINS
  14.  
  15. DATABASES = {
  16. 'default': {
  17. 'ENGINE': 'django.db.backends.postgresql_psycopg2',# Add 'postgresql_psycopg2','MysqL','sqlite3' or 'oracle'.
  18. 'NAME': 'cms1',# Or path to database file if using sqlite3.
  19. 'USER': 'cms',# Not used with sqlite3.
  20. 'PASSWORD': 'cms',# Not used with sqlite3.
  21. 'HOST': '',# Set to empty string for localhost. Not used with sqlite3.
  22. 'PORT': '',# Set to empty string for default. Not used with sqlite3.
  23. }
  24. }
  25.  
  26. # Local time zone for this installation. Choices can be found here:
  27. # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
  28. # although not all choices may be available on all operating systems.
  29. # In a Windows environment this must be set to your system time zone.
  30. TIME_ZONE = 'Europe/Rome'
  31.  
  32. # Language code for this installation. All choices can be found here:
  33. # http://www.i18nguy.com/unicode/language-identifiers.html
  34. LANGUAGE_CODE = 'it-it'
  35.  
  36. SITE_ID = 1
  37.  
  38. # If you set this to False,Django will make some optimizations so as not
  39. # to load the internationalization machinery.
  40. USE_I18N = True
  41.  
  42. # If you set this to False,Django will not format dates,numbers and
  43. # calendars according to the current locale.
  44. USE_L10N = True
  45.  
  46. # If you set this to False,Django will not use timezone-aware datetimes.
  47. USE_TZ = True
  48.  
  49. # Absolute filesystem path to the directory that will hold user-uploaded files.
  50. # Example: "/home/media/media.lawrence.com/media/"
  51. MEDIA_ROOT = os.path.join(PROJECT_PATH,"media")
  52.  
  53. # URL that handles the media served from MEDIA_ROOT. Make sure to use a
  54. # trailing slash.
  55. # Examples: "http://media.lawrence.com/media/","http://example.com/media/"
  56. MEDIA_URL = '/media/'
  57.  
  58. # Absolute path to the directory static files should be collected to.
  59. # Don't put anything in this directory yourself; store your static files
  60. # in apps' "static/" subdirectories and in STATICFILES_DIRS.
  61. # Example: "/home/media/media.lawrence.com/static/"
  62. STATIC_ROOT = os.path.join(PROJECT_PATH,"static")
  63. STATIC_URL = "/static/"
  64.  
  65.  
  66. # Additional locations of static files
  67. STATICFILES_DIRS = (
  68. os.path.join(PROJECT_PATH,"static_auto"),# Put strings here,like "/home/html/static" or "C:/www/django/static".
  69. # Always use forward slashes,even on Windows.
  70. # Don't forget to use absolute paths,not relative paths.
  71. )
  72.  
  73. # List of finder classes that know how to find static files in
  74. # varIoUs locations.
  75. STATICFILES_FINDERS = (
  76. 'django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder',# 'django.contrib.staticfiles.finders.DefaultStorageFinder',)
  77.  
  78. # Make this unique,and don't share it with anybody.
  79. SECRET_KEY = '^c2q3d8w)f#gk%5i)(#i*lwt%lm-!2=(*1d!1cf+rg&-hqi_9u'
  80.  
  81. # List of callables that know how to import templates from varIoUs sources.
  82. TEMPLATE_LOADERS = (
  83. 'django.template.loaders.filesystem.Loader','django.template.loaders.app_directories.Loader',# 'django.template.loaders.eggs.Loader',)
  84.  
  85. MIDDLEWARE_CLASSES = (
  86. 'django.middleware.common.CommonMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','cms.middleware.multilingual.MultilingualURLMiddleware','cms.middleware.page.CurrentPageMiddleware','cms.middleware.user.CurrentUserMiddleware','cms.middleware.toolbar.ToolbarMiddleware',# Uncomment the next line for simple clickjacking protection:
  87. # 'django.middleware.clickjacking.XFrameOptionsMiddleware',)
  88.  
  89. ROOT_URLconf = 'cms1.urls'
  90.  
  91. # Python dotted path to the WSGI application used by Django's runserver.
  92. WSGI_APPLICATION = 'cms1.wsgi.application'
  93.  
  94. TEMPLATE_DIRS = (
  95. os.path.join(PROJECT_PATH,"templates"),like "/home/html/django_templates" or "C:/www/django/templates".
  96. # Always use forward slashes,not relative paths.
  97. )
  98.  
  99. CMS_TEMPLATES = (
  100. ('template_1.html','Template One'),('template_2.html','Template Two'),)
  101.  
  102. TEMPLATE_CONTEXT_PROCESSORS = (
  103. 'django.contrib.auth.context_processors.auth','django.core.context_processors.i18n','django.core.context_processors.request','django.core.context_processors.media','django.core.context_processors.static','cms.context_processors.media','sekizai.context_processors.sekizai',)
  104.  
  105. LANGUAGES = [
  106. ('it','Italiano'),('en','English'),]
  107.  
  108. INSTALLED_APPS = (
  109. 'django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.sites','django.contrib.messages','django.contrib.staticfiles','cms',#django CMS itself
  110. 'mptt',#utilities for implementing a modified pre-order traversal tree
  111. 'menus',#helper for model independent hierarchical website navigation
  112. 'south',#intelligent schema and data migrations
  113. 'sekizai',#for javascript and css management
  114. #'cms.plugins.file','cms.plugins.flash','cms.plugins.googlemap','cms.plugins.link',#'cms.plugins.picture','cms.plugins.snippet','cms.plugins.teaser','cms.plugins.text',#'cms.plugins.video','cms.plugins.twitter','filer','cmsplugin_filer_file','cmsplugin_filer_folder','cmsplugin_filer_image','cmsplugin_filer_teaser','cmsplugin_filer_video','easy_thumbnails','PIL',# Uncomment the next line to enable the admin:
  115. 'django.contrib.admin',# Uncomment the next line to enable admin documentation:
  116. # 'django.contrib.admindocs',)
  117.  
  118. # A sample logging configuration. The only tangible logging
  119. # performed by this configuration is to send an email to
  120. # the site admins on every HTTP 500 error when DEBUG=False.
  121. # See http://docs.djangoproject.com/en/dev/topics/logging for
  122. # more details on how to customize your logging configuration.
  123. LOGGING = {
  124. 'version': 1,'disable_existing_loggers': False,'filters': {
  125. 'require_debug_false': {
  126. '()': 'django.utils.log.requiredebugFalse'
  127. }
  128. },'handlers': {
  129. 'mail_admins': {
  130. 'level': 'ERROR','filters': ['require_debug_false'],'class': 'django.utils.log.AdminEmailHandler'
  131. }
  132. },'loggers': {
  133. 'django.request': {
  134. 'handlers': ['mail_admins'],'level': 'ERROR','propagate': True,},}
  135. }

当我尝试上传图片时,在剪贴板部分我没有缩略图,只是一个“未定义”的消息:

这是尝试上传时的runserver控制台:

  1. [20/Oct/2012 15:15:56] "POST /admin/filer/clipboard/operations/upload/?qqfile=29708_1306856312320_7706073_n.jpg HTTP/1.1" 500 248133
  2. [20/Oct/2012 15:15:56] "GET /it/admin/filer/folder/unfiled_images/undefined HTTP/1.1" 301 0
  3. [20/Oct/2012 15:15:56] "GET /it/admin/filer/folder/unfiled_images/undefined/ HTTP/1.1" 404 1739

此外,这是项目文件系统:

  1. cms1
  2. ├── cms1
  3. ├── __init__.py
  4. ├── __init__.pyc
  5. ├── media
  6. └── filer_public
  7. └── 2012
  8. └── 10
  9. └── 20
  10. ├── 29708_1306856312320_7706073_n_1.jpg
  11. ├── 29708_1306856312320_7706073_n_2.jpg
  12. ├── 29708_1306856312320_7706073_n_3.jpg
  13. ├── 29708_1306856312320_7706073_n_4.jpg
  14. ├── 29708_1306856312320_7706073_n_5.jpg
  15. ├── 29708_1306856312320_7706073_n_6.jpg
  16. ├── 29708_1306856312320_7706073_n_7.jpg
  17. ├── 29708_1306856312320_7706073_n.jpg
  18. └── torrent-client-macosx.jpg
  19. ├── settings.py
  20. ├── settings.pyc
  21. ├── static
  22. ├── static_auto
  23. ├── static_manual
  24. ├── templates
  25. ├── base.html
  26. ├── template_1.html
  27. └── template_2.html
  28. ├── urls.py
  29. ├── urls.pyc
  30. ├── wsgi.py
  31. └── wsgi.pyc
  32. └── manage.py

因此上传文件,但cms无法访问它们.这里有一个similar question,但对我这么帮助.
对我这个问题的任何帮助都会非常有帮助.

谢谢,卢克

解决方法

错误是因为您安装了PIL而没有JPEG / PNG支持.
您需要安装以下软件包
  1. sudo apt-get install python-imaging python-dev libjpeg8 libjpeg8-dev libfreetype6 libfreetype6-dev

然后卸载PIL pip卸载PIL

我建议使用pip安装枕头安装枕头代替PIL.确保在安装后阅读日志,应该说支持JPEG和PNG

猜你在找的Python相关文章