鍍金池/ 問答/Python  Linux  數(shù)據(jù)庫(kù)/ 關(guān)于同級(jí)目錄下模塊的引入問題報(bào)錯(cuò), django,2.0的setting.py里

關(guān)于同級(jí)目錄下模塊的引入問題報(bào)錯(cuò), django,2.0的setting.py里INSTALLTED_APPS讀不到自定義模塊?

clipboard.png
關(guān)于同級(jí)目錄下模塊的引入問題請(qǐng)問為什么報(bào)錯(cuò),
sys.path.insert(0,BASE_DIR)
將應(yīng)用包加入系統(tǒng)變量, 便于模塊導(dǎo)入
sys.path.insert(0,os.path.join(BASE_DIR, 'db_tools'))
sys.path.insert(0,os.path.join(BASE_DIR, 'apps'))
sys.path.insert(0,os.path.join(BASE_DIR, 'extra_apps'))

clipboard.png
補(bǔ)充:
發(fā)現(xiàn)shell中引入沒問題,但是外部文件中執(zhí)行提示模塊無法被引入

from goods.models import Goods

外部文件:
python models.py:
Traceback (most recent call last):
File "models.py", line 6, in <module>

from goods.models import Goods

ModuleNotFoundError: No module named 'goods'
django,2.0的setting.py里INSTALLTED_APPS讀不到自定義模塊?
clipboard.png

 filter_class = self.get_filter_class(view, queryset)
  File "/root/Virtualenv/venv3_ETC/lib/python3.6/site-packages/django_filters/rest_framework/backends.py", line 30, in get_filter_class
filter_model = filter_class.Meta.model
AttributeError: type object 'Meta' has no attribute 'model'

clipboard.png

clipboard.png` """

    Return the django-filters `FilterSet` used to filter the queryset.
    """
    filter_class = getattr(view, 'filter_class', None)
    filter_fields = getattr(view, 'filter_fields', None)
    if filter_class:
        filter_model = filter_class.Meta.model ...
        
        assert issubclass(queryset.model, filter_model), \
            'FilterSet model %s does not match queryset model %s' % \
            (filter_model, queryset.model)
        return filter_class

? Local vars`

回答
編輯回答
落殤

看圖如上截圖+我自己的推測(cè),理解如下:

  1. 按你的引用,goods應(yīng)該是一個(gè)package?即目錄下有一個(gè)__init__.py
  2. goods下有一個(gè)模塊models,models中有個(gè)類Goods
  3. 在apps根目錄新建__init__.py,即apps也是一個(gè)package
  4. models.py修改成
sys.path.append("../..")
from apps.goods.models import MyGoods
2018年5月23日 02:58