我在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」 –