生产中的相同代码库在我的服务器日志中给出了以下错误。问题似乎与我在Django CMS中使用的百日草博客应用有关。这是什么错误,如何解决?
我重新安装了这个百日草并且仍然得到错误,奇怪的是该问题没有出现在使用相同数据库的本地计算机上。
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 255, in __call__
response = self.get_response(request)
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 178, in get_response
response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 220, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 342, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/srv/project/cherry/cherry/core/urls.py", line 6, in <module>
admin.autodiscover()
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/__init__.py", line 29, in autodiscover
import_module('%s.admin' % app)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/zinnia/admin/__init__.py", line 6, in <module>
from zinnia.admin.entry import EntryAdmin
File "/usr/local/lib/python2.7/dist-packages/zinnia/admin/entry.py", line 25, in <module>
from zinnia.admin.forms import EntryAdminForm
File "/usr/local/lib/python2.7/dist-packages/zinnia/admin/forms.py", line 17, in <module>
class CategoryAdminForm(forms.ModelForm):
File "/usr/local/lib/python2.7/dist-packages/zinnia/admin/forms.py", line 44, in CategoryAdminForm
class Meta:
File "/usr/local/lib/python2.7/dist-packages/zinnia/admin/forms.py", line 49, in Meta
fields = forms.ALL_FIELDS
**AttributeError: 'module' object has no attribute 'ALL_FIELDS'**
来自/usr/local/lib/python2.7/dist-packages/zinnia/admin/forms.py的服务器上的文件:
"""Forms for Zinnia admin"""
from django import forms
from django.db.models import ManyToOneRel
from django.db.models import ManyToManyRel
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
from mptt.forms import TreeNodeChoiceField
from zinnia.models.entry import Entry
from zinnia.models.category import Category
from zinnia.admin.widgets import MPTTFilteredSelectMultiple
from zinnia.admin.fields import MPTTModelMultipleChoiceField
class CategoryAdminForm(forms.ModelForm):
"""
Form for Category's Admin.
"""
parent = TreeNodeChoiceField(
label=_('Parent category'),
level_indicator='|--', required=False,
empty_label=_('No parent category'),
queryset=Category.objects.all())
def __init__(self, *args, **kwargs):
super(CategoryAdminForm, self).__init__(*args, **kwargs)
rel = ManyToOneRel(Category._meta.get_field('tree_id'),
Category, 'id')
self.fields['parent'].widget = RelatedFieldWidgetWrapper(
self.fields['parent'].widget, rel, self.admin_site)
def clean_parent(self):
"""
Check if category parent is not selfish.
"""
data = self.cleaned_data['parent']
if data == self.instance:
raise forms.ValidationError(
_('A category cannot be parent of itself.'))
return data
class Meta:
"""
CategoryAdminForm's Meta.
"""
model = Category
fields = forms.ALL_FIELDS
class EntryAdminForm(forms.ModelForm):
"""
Form for Entry's Admin.
"""
categories = MPTTModelMultipleChoiceField(
label=_('Categories'), required=False,
queryset=Category.objects.all(),
widget=MPTTFilteredSelectMultiple(_('categories'), False,
attrs={'rows': '10'}))
def __init__(self, *args, **kwargs):
super(EntryAdminForm, self).__init__(*args, **kwargs)
rel = ManyToManyRel(Category, 'id')
self.fields['categories'].widget = RelatedFieldWidgetWrapper(
self.fields['categories'].widget, rel, self.admin_site)
self.fields['sites'].initial = [Site.objects.get_current()]
class Meta:
"""
EntryAdminForm's Meta.
"""
model = Entry
fields = forms.ALL_FIELDS
贝壳:
Python 2.7.3 (default, Sep 26 2013, 20:03:06)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.VERSION
(1, 5, 1, 'final', 0)
>>> from django.forms import ALL_FIELDS
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name ALL_FIELDS
>>>
答案 0 :(得分:1)
Zinnia v0.14与django 1.5不兼容
http://docs.django-blog-zinnia.com/en/latest/notes/compatibility.html