views.py文件:
from django.http import HttpResponse
from django.template import loader
def index(request):
template = loader.get_template('upload/testpage.html')
return HttpResponse(template.render)
app / templates / app / testpage.html文件:
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<input type="file" id="upload" name="upload" style="visibility: hidden; width: 1px; height: 1px" multiple />
<a href="" onclick="document.getElementById('upload').click(); return false">Upload</a>
</body>
</html>
app / urls.py文件:
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),]
project / urls.py文件:
from django.conf.urls import include, url
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^upload/', include('upload.urls')),]
在本地服务器上运行文件时出现错误127.0.0.1:8000/app of&#34; TemplateDoesNotExist at / app /&#34;
如何解决这个问题?
答案 0 :(得分:0)
试试这个,
from django.shortcuts import render
def index(request):
return render(request, 'app/testpage.html')
答案 1 :(得分:0)
使用您当前的文件路径app/templates/app/testpage.html
,这个应该可行
def index(request):
template = loader.get_template('app/testpage.html')
return HttpResponse(template.render)
另一种方法是将模板路径更改为app/templates/upload/testpage.html
答案 2 :(得分:0)
我认为您未在 templtes 文件夹中创建任何上传文件夹。 如果你有 app 这样的文件夹
template = loader.get_template('app/testpage.html')
现在,您可以修复它
Map<String, Long> counts = new HashMap<>();
entireMap.forEach((k, v) ->
counts.merge(v.get("user_name"), 1L, Long::sum));