python - Django 1.11:尚未加载应用程序
问题描述
我正在学习如何使用 Django 框架进行 Web 编程,当我尝试返回模板时收到此错误消息。当我尝试加载https://www..../index2/时,一切正常。
这是我的 urls.py:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^index2/$', views.index2, name='index2'),
]
这是我的views.py:
from django.http import HttpResponse
from django.shortcuts import render
# Create your views here.
def index(request):
return render(request, 'main/index.html',)
def index2(request):
return HttpResponse("Hello, world.")
解决方案
如果您启用了调试模式,请确保您已index.html
保存。app/templates/main/index.html
异常页面将显示与paths
django 尝试加载的位置不同index.html
。
推荐阅读
- python - 当它具有文件访问权限时,为 python 执行 cron 作业失败
- angularjs - Kendo Grid 服务器端过滤将 null 作为过滤器对象发送到后端
- spring-boot - 使用 apache commons cli 无法识别的选项
- ios - 如何在swift中使用单例访问另一个控制器中的模型类值?
- android - 为什么在填充之前使用Adapter中的列表呢?
- mysql - 如何使用mysql sum() 函数计算每一行的总和?
- angular - Angular 中的依赖注入有什么用,因为它显然没有解决任何问题?
- java - 为什么 Iterators.size() 使迭代器为空?
- r - 告诉哪些行是不同的,同时保持 ID 变量
- kubernetes - Fetching Stackdriver Monitoring TimeSeries data for a pod running on a k8s cluster on GKE using the REST API