导入错误:无法导入名称 get_model

问题描述 投票:0回答:2
File "C:\Python27\Lib\site-packages\file_picker\forms.py,line 5 in <module>
from django.db.models import Q,get_model
ImportError:cannot import name get_model

我正在使用 django 1.9.7 和 file_picker 0.2.2 我似乎没有任何解决方案来解决这个问题

python django file picker
2个回答
9
投票

尝试使用

django.apps
代替:

from django.apps import apps

apps.get_model('Model')

https://docs.djangoproject.com/en/dev/ref/applications/#django.apps.AppConfig.get_model


3
投票

试试这个,

from django.apps import apps

model_obj = apps.get_model('app_name', 'model_name')

其中“app_name”是您的应用名称,“model_name”是您的型号名称。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.