我在urls.py下面的代码Django的名称错误
from django.conf.urls import url
from django.contrib import admin
from django.conf.urls import include
urlpatterns = [
url(r'^testModule/',include(testModule.urls)),
url(r'^admin/', admin.site.urls),
]
和testModule是我的应用程序的名字,其中包括:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$',views.index,name='index'),
]
我的views.py是
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello")
# Create your views here.
但是,运行服务器时出现以下错误:
line 20: url(r'^testModule/',include(testModule.urls)), NameError: name 'testModule' is not defined
“from django.contrib import testModule”。我输入它。现在我得到一个错误:无法导入名称testModule – Deesha
是的。你为什么会认为这是'django.contrib'?这大概是在你的应用程序。 –
即只是使用“导入testModule”或“导入testModule.urls” –