Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 属性错误-模块';http.request';没有属性';META&x27;_Python_Django - Fatal编程技术网

Python 属性错误-模块';http.request';没有属性';META&x27;

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

我犯了这个错误,但我也犯了同样的错误:

属性错误/课程/ 模块'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(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-不用担心,尽情享受!