django在pycharm中urls.py下的路径报错问题,
出现该错误,ValueError: attempted relative import beyond top-level package
文件结构
该写法是正确的
urls.py在blog下
from django.contrib import admin
from django.urls import path
from django.conf.urls import include, url
from article.views import home
urlpatterns = [
# ex: /admin/
path('admin/', admin.site.urls),
# ex: /
path('', home, name='home'),
# ex: /article/
path('article/', include('article.urls')),
]
上述代码中from article.views import home在pycharm中会报错,但是能运行出来
而将该代码改成from ..article.views import home不会报错但是会出现运行错误