简体   繁体   中英

ImportError: attempted relative import beyond top-level package django

I'm writing a site on Django and faced the problem that when relative importing from a directory located in the same directory as the directory in which the import is carried out, the following error appears:

ImportError: attempted relative import beyond top-level package

here is my import,which is in the file online_book/shop-cart/cart.py

from ..books.models import Book

the Book model is in the file online-book/books/models.py

这是我的项目结构

help me find solution to this problem please

imports are relative to where the manage.py is
so your import should be like this:

from books.models import Book

Set dir online_book as root directory in settings

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM