Python 属性错误-模块';http.request';没有属性';META&x27;
我犯了这个错误,但我也犯了同样的错误: 属性错误/课程/ 模块'django.http.request'没有属性'META' 错误发生在:Python 属性错误-模块';http.request';没有属性';META&x27;,python,django,Python,Django,我犯了这个错误,但我也犯了同样的错误: 属性错误/课程/ 模块'django.http.request'没有属性'META' 错误发生在: from django.shortcuts import render from django.http import request from django.http import HttpResponse from .models import Course # Create your views here. def course_list(respo
from django.shortcuts import render
from django.http import request
from django.http import HttpResponse
from .models import Course
# Create your views here.
def course_list(response):
courses = Course.objects.all()
return render(request, 'courses/course_list.html',{'courses':courses})
# output=', '.join([str(course) for course in courses])
# return HttpResponse(output)
但是服务器没有显示任何问题
Performing system checks...
System check identified no issues (0 silenced).
September 13, 2016 - 13:51:18
Django version 1.10.1, using settings 'learning_site.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
您的函数参数称为
response
,但随后您使用导入的模块request
,将字段参数更改为调用request
,或将其在函数中的用法更改为response
def course_list(request):
courses = Course.objects.all()
return render(request, 'courses/course_list.html',{'courses':courses})
def course_list(response):
courses = Course.objects.all()
return render(response, 'courses/course_list.html',{'courses':courses})
(而且,完全可能您根本不需要导入
请求)是的,我意识到了这一点。我没有上完这门课,但我是凭冲动去做的。很好,不!再次感谢@DevBingo-不用担心,尽情享受!