Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Nik Cochran
Nik Cochran
14,620 Points

SystemError: Parent module '' not loaded, cannot perform relative import

I'm doing the Django basics course and trying to follow along locally. When I run the below code I get the error: SystemError: Parent module '' not loaded, cannot perform relative import

I feel like I'm just doing something stupid but not sure what. Any help would be much appreciated.

views.py

from django.http import HttpResponse

def hello_world(request): return HttpResponse('Hello World')

urls.py

from django.conf.urls import include, url from django.contrib import admin

from . import views

urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^$', views.hello_world), ]

1 Answer

I am guessing that the line

"from . import views" is what is giving you the problem. The "." indicates a relative file path, and the error says it cant do a relative import.

Try giving the actual name of the module you are using.

Hope this helps!