0

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?

WandPoint
  • 23
  • 4

1 Answers1

0

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.

Jalaj
  • 463
  • 3
  • 16