When i want to save this django file:
from django.urls import path
from . import views
urlpatterns = [
path('index/', views.index, name='main-view')
]
I get an error:
"ImportError: attempted relative import with no known parent package"
What should I do with it?
Try creating an __init__.py
file in the same directory as your file. Then add import views
in that __init__.py
file.
It should work but if it doesn't then try adding the following snippet in your code:
import sys
sys.path.append('.')
EDIT : This snippet should be at the top of the file, before other imports.
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.