【发布时间】:2017-09-09 05:20:31
【问题描述】:
我现在已经尝试两次将第二个应用程序添加到我的 Django 站点上,但它会导致某种错误。
我已按照 youtube 的说明进行操作,这对我有很大帮助,但现在我无法添加第二页。我的第一个工作正常。
这是我的主要 url.py:
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^table/', include('table.urls')),
url(r'^', include('login.urls')),
]
这是我的主要设置.py:
INSTALLED_APPS = [
'login',
'table',
....
TEMPLATES = [
{
'BACKEND': 'django.templates.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.templates.context_processors.debug',
'django.templates.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
这是我的工作页面 url.py:
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
]
这是我的工作页面view.py:
from django.shortcuts import render
def index(request):
return render(request,'login/login.html', {'content': ['username',
'password']} )
这是我的非工作页面 url.py:
from django.conf.urls import url, include
from . import views
urlpatterns = [
url(r'^$', views.index, name = 'index'),
]
这是我的非工作页面view.py:
from django.shortcuts import render
from django.http import HttpResponse
def index(request):
return render(request,'table/table.html')
到目前为止,我认为索引(请求)是一个问题,因为它们都具有名称“视图”和相同的函数名称......?
我不知道在“错误页面”上看哪里,也不知道给你们看什么,对不起。我很感激任何帮助。谢谢。
"在处理上述异常('django')的过程中,又出现了一个异常:
C:\python36\lib\site-packages\django\core\handlers\exception.py 在内部
响应 = get_response(请求) ...
▼ 局部变量
变量值
除外
ModuleNotFoundError("没有名为 'django.templates' 的模块",)
获取响应
>>>
>
要求
"
编辑:我已经命名了我所有的模板文件夹模板,一直如此。虽然我在第二个应用程序中创建它时错误地将它命名为没有 s ,但它通过重构进行了更改。
我认为这是我现在的错误:
异常类型:ModuleNotFoundError at / 异常值:没有名为“django.templates”的模块
【问题讨论】:
-
我不确定,但是考虑到错误 No module named 'django.templates' 我认为您可能在该应用程序的某处的导入语句中写了一个错误,或者设置文件中的错字。有一个模块 django.template,但没有 django.templates。
-
是的,如果我理解正确的话,我相信这是我的错误消息:异常类型:ModuleNotFoundError at / 异常值:没有名为“django.templates”的模块
-
找到了吗?如果没有,请检查您的 TEMPLATES 设置(设置了一些 django.template.x 模块)或者可能是您的 views.py 或 forms.py 文件导入语句:from django.templates import x。您很可能需要在某处将 django.templates 更改为 django.template。
-
天哪,它有助于从设置文件中删除“s”!我只是觉得哇。 :O 非常感谢!!
-
不客气,很高兴我能帮上忙!
标签: django web python-3.5