how to resolve django : ImportError: cannot import name 'parse_header' from 'django.http.multipartparser'

huangapple go评论85阅读模式
英文:

how to resolve django : ImportError: cannot import name 'parse_header' from 'django.http.multipartparser'

问题

I see that you'd like a translation of the error message and the relevant code. Here it is:

错误信息:

我的应用程序在几天前还正常运行,但突然间我看到了这个错误,不确定它是什么意思,请帮助。

错误:

File "/myproj/myapp/urls.py", line 8, in <module>
from rest_framework import routers
File "/usr/local/lib/python3.8/site-packages/rest_framework/routers.py", line 22, in <module>
from rest_framework import views
File "/usr/local/lib/python3.8/site-packages/rest_framework/views.py", line 15, in <module>
from rest_framework.request import Request
File "/usr/local/lib/python3.8/site-packages/rest_framework/request.py", line 17, in <module>
from django.http.multipartparser import parse_header
ImportError: cannot import name 'parse_header' from 'django.http.multipartparser' (/usr/local/lib/python3.8/site-packages/django/http/multipartparser.py)


我在urls.py文件的第8行是:
```python
from rest_framework import routers

我可以看到在multipartparser.py文件中有parse_header方法,附上multipartparser文件链接

英文:

My application was running fine till few days back, but now all of a sudden i'm seeing this error and not sure what it means, please help.

Error:

File &quot;/myproj/myapp/urls.py&quot;, line 8, in &lt;module&gt;
from rest_framework import routers
File &quot;/usr/local/lib/python3.8/site-packages/rest_framework/routers.py&quot;, line 22, in &lt;module&gt;
from rest_framework import views
File &quot;/usr/local/lib/python3.8/site-packages/rest_framework/views.py&quot;, line 15, in &lt;module&gt;
from rest_framework.request import Request
File &quot;/usr/local/lib/python3.8/site-packages/rest_framework/request.py&quot;, line 17, in &lt;module&gt;
from django.http.multipartparser import parse_header
ImportError: cannot import name &#39;parse_header&#39; from &#39;django.http.multipartparser&#39; (/usr/local/lib/python3.8/site-packages/django/http/multipartparser.py)

my line 8 of urls.py is:

from rest_framework import routers

and i could see the parse_header method in the multipartparser.py file PFA

multipartparser file

答案1

得分: 9

以下是已翻译的内容:

在我看来,这可能是由两个原因引起的:

  1. 安装 Django 本身出现问题,这种情况下,我建议使用 pip install django 卸载然后重新安装 Django
  2. Djangodjangorestframework 之间的版本不匹配,请检查这两个包的版本是否兼容。

请找到附在下面的发行说明文档链接:

https://www.django-rest-framework.org/community/release-notes/

英文:

In my opinion, this can be caused by two things:

  1. Problem with installing Django itself, and in this case I would recommend uninstalling and then reinstalling Django using pip install django
  2. Version mismatch between Django and djangorestframework, check if the versions of these two packages are compatible.

Please find the documentation link for the release notes attached below:

https://www.django-rest-framework.org/community/release-notes/

huangapple
  • 本文由 发表于 2023年4月17日 20:23:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035125.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定