我收到了这个错误,但我完全一样:
/ courses /的AttributeError 模块' 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.
答案 0 :(得分:2)
您的函数参数被称为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})