Problem importing a module in django v4.1.7, pydroid3 python v3.9.7

49 Views Asked by At

My urls.py and views.py files are in the same directory (my_app), after importing the views.py file from my urls.py file, whenever I try to start the development server I get a module import error: no module named views but when I compile and run the urls.py file I get an import error: attempted relative import with no parent package.

This is the code from urls.py:



from django.urls import path

from . import views

urlpatterns = [

path('', index, name='index')

]

I tried modifying the import statement for views into: from views import index and that removed the compilation error but not the server error.

1

There are 1 best solutions below

0
weAreStarsDust On

from .views import index should fix problem

from .views import index

urlpatterns = [
    path('', index, name='index')
]