pycharm 利用 django进行web开发出现:“NameError at / name 'HttpResponse' is not defined”

新建的Django成功实现网页编辑了,但是更改url 配置后,再次运行却出现:

NameError at /
name 'HttpResponse' is not defined
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.11.5
Exception Type: NameError
Exception Value:
name 'HttpResponse' is not defined
Exception Location: D:\b\untitled12\app01\views.py in index, line 5
Python Executable: C:\Users\Administrator\AppData\Local\Programs\Python\Python36-32\python.exe
Python Version: 3.6.0

重新编制崭新的django 却不能再次成功建立网页,
请帮忙分析,是什么原因,怎么解决
是否在运行过程中,pycharm 的某些文件被更改了?

因为你没有导入HttpResponse。需要在views.py的顶部添加:

from django.shortcuts import HttpResponse

建议你跟着这个教程走一遍:刘江的Django教程

温馨提示:答案为网友推荐,仅供参考
相似回答