You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django渲染HTML页面报错:'module' object is not callable 求助

问题解决方法

错误根源

你在views.py中错误导入了urllib.response模块,并尝试将这个模块作为函数调用,这直接导致了'module' object is not callable的类型错误。同时你已经导入了Django提供的render函数,却没有正确使用它。

修正后的views.py代码

from django.shortcuts import render

def index(request):
    return render(request, 'good/try.html')

关键说明

  • 移除无用的from urllib import response和from django.http import HttpRequest导入,render函数会自动处理传入的request对象,无需额外导入HttpRequest。
  • 确保模板文件try.html位于你的Django应用目录下的templates/good/路径中(如果templates目录不存在,手动创建即可,Django默认会扫描应用内的templates文件夹查找模板)。

你的urls.py和HTML模板代码没有问题,修正views.py后重新运行服务即可正常访问页面。

内容的提问来源于stack exchange,提问作者MSAFIRI MCHOMVU

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 20:36:38