[Django]-"from . import views": Unresolved import

3👍

The project was created with the PyDev wizard as a Django project. When it was created, the folder polls is not a source folder. As a result, no code analysis was performed. So I changed the folder polls (which is inside the project folder mysite) to a source folder. Now the code was analyzed and unresolved import error was raised.

The fix is to change polls back to a normal folder (removed from PYTHONPATH), and instead set the top-level project folder mysite as a source folder. Now both PyDev and Django work well.

3👍

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.index, name='index'),
]

what you need is to change the. with your parent folder. that’s what I did to solve my problem. for example the folder of my project is called blog so I made
Do this : from blog import views instead of from . import views

from django.conf.urls import url
from blog import views
urlpatterns = [
    url(r'^$', views.post_list, name='post_list'),
    url(r'^post/(?P<pk>[0-9]+)/$', views.post_detail, name='post_detail'),
]

Leave a comment