我正在尝试按照此处的步骤操作:
http://dev.svetlyak.ru/optional-email-in-django-comments-en/
使 Django 评论应用程序中的“电子邮件地址”字段可选。具体来说,我创建了一个名为“mycomments.py”的文件,其内容如下:
from django import forms
from django.contrib.comments.forms import CommentDetailsForm
from django.utils.translation import ungettext, ugettext_lazy as _
class CommentForm(CommentDetailsForm):
email = forms.EmailField(label=_("Email address"), required=False)
def get_form():
return CommentForm
并将其放在我的 Django 项目的根文件夹中(包含 manage.py 和 settings.py 的同一文件夹)。然后,我在 settings.py 文件中添加了“mycomments”,如下所示:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.comments',
'blogs',
'mycomments',
)
COMMENTS_APP = 'mycomments'
但是当我执行“python manage.py runserver”时,出现以下错误:
Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x8bb208c>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 146, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 61, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 83, in load_app
if not module_has_submodule(app_module, 'models'):
File "/usr/local/lib/python2.7/dist-packages/django/utils/module_loading.py", line 17, in module_has_submodule
for entry in package.__path__: # No __path__, then not a package.
AttributeError: 'module' object has no attribute '__path__'
并且开发服务器没有启动。我做错什么了吗?