英文:
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 "/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)
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
答案1
得分: 9
以下是已翻译的内容:
在我看来,这可能是由两个原因引起的:
- 安装
Django
本身出现问题,这种情况下,我建议使用pip install django
卸载然后重新安装Django
。 Django
和djangorestframework
之间的版本不匹配,请检查这两个包的版本是否兼容。
请找到附在下面的发行说明文档链接:
https://www.django-rest-framework.org/community/release-notes/
英文:
In my opinion, this can be caused by two things:
- Problem with installing
Django
itself, and in this case I would recommend uninstalling and then reinstallingDjango
usingpip install django
- Version mismatch between
Django
anddjangorestframework
, 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/
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论