首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >django.core.exceptions.ImproperlyConfigured

django.core.exceptions.ImproperlyConfigured
EN

Stack Overflow用户
提问于 2014-09-29 23:04:55
回答 3查看 31.3K关注 0票数 18

我最近搬到了另一台机器上,不得不再次从subversion中检出我的项目,但我非常确定这台计算机安装了Django 1.8,该项目预期为1.7。

我尝试将我的数据库与代码同步以创建所需的表,但得到以下错误。

代码语言:javascript
复制
C:\Users\jont\Documents\ATP\Webapp>manage.py syncdb
C:\Python27\lib\site-packages\admin_tools\utils.py:9: RemovedInDjango19Warning:      
django.utils.importlib will be removed in Django 1.9.
from django.utils.importlib import import_module

c:\users\jont\documents\django-trunk\django\contrib\contenttypes\models.py:148:  
RemovedInDjango19Warning: Model class django.contrib.contenttypes.models.ContentType doesn't de
her isn't in an application in INSTALLED_APPS or else was imported before its application was  
loaded. This will no longer be supported in Django 1.9.
class ContentType(models.Model):

C:\Python27\lib\site-packages\admin_tools\dashboard\modules.py:8: RemovedInDjango19Warning: The 
django.forms.util module has been renamed. Use django.forms.utils instead.
from django.forms.util import flatatt

C:\Python27\lib\site-packages\django_tables2\tables.py:171: RemovedInDjango19Warning: SortedDict
is deprecated and will be removed in Django 1.9. attrs["base_columns"] =  
SortedDict(parent_columns)

C:\Python27\lib\site-packages\django_tables2\tables.py:193: RemovedInDjango19Warning: SortedDict 
is deprecated and will be removed in Django 1.9.
attrs["base_columns"].update(SortedDict(cols))

Traceback (most recent call last):
File "C:\Users\jont\Documents\ATP\Webapp\manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "c:\users\jont\documents\django-trunk\django\core\management\__init__.py", line 336, in
execute_from_command_line
utility.execute()
File "c:\users\jont\documents\django-trunk\django\core\management\__init__.py", line 310, in 
execute
django.setup()
File "c:\users\jont\documents\django-trunk\django\__init__.py", line 23, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\users\jont\documents\django-trunk\django\apps\registry.py", line 115, in populate
app_config.ready()
File "c:\users\jont\documents\django-trunk\django\contrib\admin\apps.py", line 22, in ready
self.module.autodiscover()
File "c:\users\jont\documents\django-trunk\django\contrib\admin\__init__.py", line 24, in  
autodiscover
autodiscover_modules('admin', register_to=site)
File "c:\users\jont\documents\django-trunk\django\utils\module_loading.py", line 73, in 
autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\jont\Documents\ATP\Webapp\jobs\admin.py", line 4, in <module>
from jobs.views import registration
File "C:\Users\jont\Documents\ATP\Webapp\jobs\views.py", line 12, in <module>
from jobs.forms import ApplicantForm, JobForm, \
File "C:\Users\jont\Documents\ATP\Webapp\jobs\forms.py", line 8, in <module>
class JobForm(forms.ModelForm):
File "c:\users\jont\documents\django-trunk\django\forms\models.py", line 272, in __new__
"needs updating." % name
django.core.exceptions.ImproperlyConfigured: Creating a ModelForm without either the 'fields'   attribute or the 'exclude' attribute is prohibited; form JobForm needs updating.

django.core.exceptions.ImproperlyConfigured: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form JobForm needs updating.
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-09-29 23:22:32

与提到的错误一样,您需要显式排除并指定字段,即

尝尝这个

代码语言:javascript
复制
class JobForm(models.ModelForm):
    #fields

    class Meta:
        model = Job
        fields = "__all__" 

它将包括所有字段

下面是相关的documentation (release notes 1.6)

以前,如果希望ModelForm使用模型上的所有字段,只需省略Meta.fields属性,就会使用所有字段。

这可能会导致安全问题,其中字段被添加到模型中,并且无意中自动变为可由最终用户编辑。在某些情况下,特别是在布尔型字段中,这个问题可能是完全不可见的。这是批量分配漏洞的一种形式。

因此,不推荐使用此行为,并且强烈建议您使用Meta.exclude选项。相反,所有要包含在表单中的字段都应该在field属性中显式列出。

如果此安全性问题确实不适用于您的情况,则有一种快捷方式可以明确指示应使用所有字段-对字段属性使用特殊值“__all__

票数 69
EN

Stack Overflow用户

发布于 2015-04-20 14:04:36

您可以在Django1.7的ModelForm中设置字段或排除字段。它在1.8中发生了变化,您应该在ModelForm中的Meta类中设置字段或排除字段。

代码语言:javascript
复制
class JobForm(models.ModelForm):
#fields

class Meta:
    model = Job
    fields = "__all__" 
票数 5
EN

Stack Overflow用户

发布于 2014-09-29 23:22:16

升级到Django 1.7似乎可以做到这一点。似乎没有一种简单的方法来调整代码以适应Django 1.8。

票数 -6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26103005

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档