请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

问题已解决

TemplateDoesNotExist at /image

项目结构

https://img1.sycdn.imooc.com//szimg/59f7f404000171fa03160381.jpghttps://img1.sycdn.imooc.com//szimg/59f7f49e00014c1102930336.jpg

有两个view文件一个是view.py,另一个我命名为wview.py.

wview.py文件内容

from django.http import HttpResponse
from django.template import loader

from .models import ImageItems


def index(request):
    image_list = ImageItems.objects.order_by('-pk')[:5]
    template = loader.get_template('fish/index.html')
    context = {
        'image_list': image_list,
    }
    return HttpResponse(template.render(context, request))

https://img1.sycdn.imooc.com//szimg/59f7f4730001cf8a06310163.jpg

index.html文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>index</title>
</head>
<body>
{% if image_list %}
    <ul>
 {% for image in image_list %}
        <li><a href="/fish/{{ image.image_select }}/">{{ image.image_name }}</a></li>
 {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}
</body>
</html>

urls.py

from django.conf.urls import url
from django.contrib import admin

from django.conf.urls import include
from fish.views import *
from fish import wviews
from rest_framework.authtoken import views

# Routers provide an easy way of automatically determining the URL conf.



urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^image', wviews.index)
]

然后我访问网址127.0.0.1:8000/image

https://img1.sycdn.imooc.com//szimg/59f7f5f6000109c507760485.jpg

老师,感觉是fish/index.html那里错了

把问题写着写着发现应该调整Templates文件夹的位置

https://img1.sycdn.imooc.com//szimg/59f7f70c0001b2c903210351.jpg

正在回答 回答被采纳积分+3

1回答

bobby 2017-11-01 14:36:13

好的,

0 回复 有任何疑惑可以回复我~

相似问题

登录后可查看更多问答,登录/注册

问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信