gpt4 book ai didi

python - AttributeError - 模块 'django.http.request' 没有属性 'META'

转载 作者:行者123 更新时间:2023-12-02 04:06:11 26 4
gpt4 key购买 nike

我得到了这个错误,但我做了完全一样的:

AttributeError at /courses/ module 'django.http.request' has no attribute '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})

关于python - AttributeError - 模块 'django.http.request' 没有属性 'META',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39465214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com