当前位置: 首页 > 知识库问答 >
问题:

django Attributeeror “WSGI请求”对象没有属性“获取”

祖迪
2023-03-14

//id找不到错误点,并且没有搜索解决方案

属性错误在 /product/3'WSGIRequest'对象没有属性'get'请求方法:GET请求URL:http://127.0.0.1:8000/product/3Django版本:3.1.6异常类型:属性错误异常值:
'WSGIRequest'对象没有属性'get'异常位置:C:\用户\vudgh\anaconda3\lib\site-pack\django\form\widgets.py,第652行,value_from_datadictPython可执行文件:C:\用户\vudgh\anaconda3\python.exePython版本:3.8.5 Python路径:
['C:\Pytion_WorkSpoace\oto_shop','C:\用户\vudgh\anaconda3\python38.zip','C:\用户\vudgh\anaconda3\lib','C:\用户\vudgh\anaconda3\lib','C:\用户\vudgh\anaconda3','C:\用户\vudgh\AppData\漫游\Python\\anaconda3\lib\site-包\win32','C:\用户\vudgh\anaconda3\lib\site-包\win32\lib','C:\用户\vudgh\anaconda3\lib\site-包\Pythonwin']服务器时间:Thu,08 Apr 2021 22:40:36 0900

模板渲染时出错在模板C:\Pytion_WorkSpoace\oto_shop\template\base.html,第0行出错

'WSGIRequest'对象没有属性'get'

1   <!DOCTYPE html>
2   <html lang="en">
3       <head>
4           <meta charset="UTF-8">
5           <meta name="viewport" content="width=device-width, initial-scale=1.0">
6           <title>{% block title %} {% endblock %}</title>
7           <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
8           <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
9       
10      </head>

回溯切换到复制粘贴视图

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/product/3

Django Version: 3.1.6
Python Version: 3.8.5
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'users',
 'product',
 'order',
 'board',
 'rest_framework']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\Pytion_WorkSpoace\oto_shop\templates\base.html, error at line 0
   'WSGIRequest' object has no attribute 'get'
   1 : <!DOCTYPE html>
   2 : <html lang="en">
   3 :     <head>
   4 :         <meta charset="UTF-8">
   5 :         <meta name="viewport" content="width=device-width, initial-scale=1.0">
   6 :         <title>{% block title %} {% endblock %}</title>
   7 :         <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
   8 :         <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
   9 :     
   10 :     </head>


Traceback (most recent call last):
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 829, in _resolve_lookup
    current = current[bit]
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\forms\boundfield.py", line 67, in __getitem__
    raise TypeError(

During handling of the above exception (BoundField indices must be integers or slices, not str.), another exception occurred:
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\core\handlers\base.py", line 204, in _get_response
    response = response.render()
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\response.py", line 105, in render
    self.content = self.rendered_content
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 170, in render
    return self._render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 162, in _render
    return self.nodelist.render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 162, in _render
    return self.nodelist.render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 938, in render
    bit = node.render_annotated(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\defaulttags.py", line 211, in render
    nodelist.append(node.render_annotated(context))
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 905, in render_annotated
    return self.render(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\defaulttags.py", line 305, in render
    match = condition.eval(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\defaulttags.py", line 889, in eval
    return self.value.resolve(context, ignore_failures=True)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 671, in resolve
    obj = self.var.resolve(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 796, in resolve
    value = self._resolve_lookup(context)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\template\base.py", line 837, in _resolve_lookup
    current = getattr(current, bit)
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\forms\boundfield.py", line 78, in errors
    return self.form.errors.get(self.name, self.form.error_class())
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\forms\forms.py", line 172, in errors
    self.full_clean()
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\forms\forms.py", line 374, in full_clean
    self._clean_fields()
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\forms\forms.py", line 386, in _clean_fields
    value = field.widget.value_from_datadict(self.data, self.files, self.add_prefix(name))
  File "C:\Users\vudgh\anaconda3\lib\site-packages\django\forms\widgets.py", line 652, in value_from_datadict
    getter = data.get

Exception Type: AttributeError at /product/3
Exception Value: 'WSGIRequest' object has no attribute 'get'

共有1个答案

呼延曜灿
2023-03-14

您必须在“settings.py”中添加此行

INSTALLED_APPS=['…','您的应用程序',]

也许在你的middelware.settings

中间件 = [ “...”, “您的应用程序”, ]

 类似资料:
  • 我正在尝试运行布谷鸟api。布谷鸟网在我的系统上运行良好。但当我尝试布谷鸟api时,我得到了以下错误: 我试图更改api。通过添加以下代码: 但这对我没有帮助。这个问题的解决方案是什么?

  • 问题内容: 我正在尝试在Python中获取url参数。 我正在使用此代码: 但我收到此错误: 问题答案: 你想request.args在Flask中使用GET参数。 要访问通过URL(?key = value)提交的参数,可以使用args属性:

  • 这是我的密码: 这条线给了我错误 "属性错误:'浮点'对象没有属性'exp'"。X,t是Numpy ndarray。

  • 问题内容: 我正在开发Django应用程序,并且出现以下错误 我的模型是这样构造的 我应该做什么? 问题答案: 首先,您必须非常小心地重写以具有非可选参数。记住,每次从一个查询集中获取一个对象时,它将被调用! 这是您想要的正确代码: 如果您只使用该对象的子类,我强烈建议在Animal上设置abstract选项。这样可以确保不为动物创建表,而仅为绵羊(等)创建表。如果未设置abstract,则将创建

  • 我创建了这个简单的GUI: 我让用户界面启动并运行。当我点击按钮时,我在控制台上得到以下错误: 为什么设置为?

  • 问题内容: 我将Selenium webdriver(chrome)与Python结合使用,试图从网页上的所有链接中获取 href 。当我尝试以下操作时: 它设法获取所有链接,但是在get_attribute上出现错误: “ WebElement”对象没有属性“ Get_Attribute” 尽管到处都看起来很正常。 问题答案: “ Get_Attribute”属性不存在,但是“ get_attr