简体   繁体   中英

Why am I getting the error message ImportError: No module named <app>.urls?

I was recently building a django project. I have been looking through the files for a couple of hours now and can't find the problem that would result in this kind of error message. Below, I will show you all of the relevant files within the project.

base url.py:

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

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^display/', include('diplay.urls')),

]

app url.py:

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

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

app views.py:

from django.shortcuts import render
from django.http import HttpResponse

def index(request):
    return HttpResponse("<h2>HEY!</h2>")

I'm not sure why this is not working because I found a similar format online, and it seemed that every line was similar to the other one. When I try running the server, it gives me the error statement "ImportError: No module named diplay.urls". Any ideas?

Thanks in advanced.

1, make sure your app name is diplay which is same as in your base urls.py , I think maybe there is typo, should change to:

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^display/', include('display.urls')),

]

2, make sure the file name of urls should be urls.py instead of url.py in both base and app folder

Does app diplay exists or is it typo of display

> diplay.urls

Also does urls file in app exists

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM