Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django名称错误_Django_Django Urls - Fatal编程技术网

Django名称错误

Django名称错误,django,django-urls,Django,Django Urls,我的url.py中有以下代码 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是我的应用程序名,包括: f

我的url.py中有以下代码

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'),
]
我的观点是

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

def index(request):
    return HttpResponse("Hello")
# Create your views here.
但是,在运行服务器时出现以下错误:

第20行:url(r'^testModule/',include(testModule.url)), NameError:未定义名称“testModule”


您没有在主URL中导入
testModule

您没有在主URL中导入
testModule

有相同的问题,但解决方法如下:

  • 将“导入测试模块”添加到URL.py
  • 将“from django.conf.urls import url”添加到应用程序目录中的url.py,在本例中为testModule


完成后,重新加载127.0.0.1:8000时,将出现“页面未在/处找到”错误。这是因为你的应用程序的url实际上是127.0.0.1:8000/testModule有同样的问题,但解决方法如下:

  • 将“导入测试模块”添加到URL.py
  • 将“from django.conf.urls import url”添加到应用程序目录中的url.py,在本例中为testModule


完成后,重新加载127.0.0.1:8000时,将出现“页面未在/处找到”错误。这是因为你的应用程序的url实际上是127.0.0.1:8000/testModule

“from django.contrib import testModule。”我导入了它。现在我得到一个错误:无法导入名称TestModuleEyes。为什么你会认为它在“django.contrib”中?它可能在你的应用程序中。例如,只需使用“导入testModule”或“导入testModule.URL”,现在我从django.contrib导入testModule中得到另一个错误,即“AttributeError:“module”对象没有属性“URL”。“我导入了它。”。现在我得到一个错误:无法导入名称TestModuleEyes。为什么你会认为它在“django.contrib”中?它可能在你的应用程序中。例如,只需使用“import testModule”或“import testModule.URL”,现在我得到另一个错误,即“AttributeError:‘module’对象没有属性‘URL’”