首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在django中使用HTMLParser的另一个模块位置

如何在django中使用HTMLParser的另一个模块位置
EN

Stack Overflow用户
提问于 2017-08-14 07:16:28
回答 1查看 2.1K关注 0票数 2

我出现了HTMLParser的错误,在终端显示:-

从django.utils.html导入format_html,format_html_join,转义 文件"/usr/local/lib/python3.5/dist-packages/django/utils/html.py",第16行,在 从.html_parser import HTMLParser,HTMLParseError 文件"/usr/local/lib/python3.5/dist-packages/django/utils/html_parser.py",第12行,在 HTMLParseError = _html_parser.HTMLParseError AttributeError:模块“html.parser”没有属性“HTMLParseError”

使用pip3的Python3.5Django 1.7.7

根据社区的说法,他们说HTML解析器是在Python3.5版本上删除的,在我的这个旧应用程序上。

我该怎么办:-

  • 用另一种类似的方法取代HTMLParser?或
  • 我尝试过降低python版本的级别,但默认情况下它需要使用lib /usr/lib/python3.5来更改这个路径。

请帮我一下。

我的需求文件需求/Common.txt如下所示

代码语言:javascript
复制
# Core Stuff
# -------------------------------------
django>=1.7.7,<1.8
whitenoise==2.0.6

# Authentication
# -------------------------------------
django-facebook==6.0.3
PyJWT==1.4.0

# Notifications
# -------------------------------------
django-twilio-sms-2==1.0.2
hashids==1.1.0
apns==2.0.1

# Extensions
# -------------------------------------
django-extensions==1.6.1
Werkzeug==0.11.3
pytz==2015.7
django-sampledatahelper==0.3
arrow==0.7.0
requests==2.9.1
django-flat-theme==1.1.3

# Configuration
# -------------------------------------
django-sites==0.9
django-secure==1.0.1
python-dotenv==0.3.0
django-environ==0.4.0

# Models
# -------------------------------------
django-model-utils==2.4
django-uuid-upload-path==1.0.0
django-versatileimagefield==1.3
django-jsonfield==0.9.15

# Images
# -------------------------------------
Pillow==3.1.1

# For the persistance stores
# -------------------------------------
psycopg2==2.6.1

# Celery
# -------------------------------------
celery==3.1.20

# Unicode slugification
# -------------------------------------
unicode-slugify==0.1.3
django-autoslug==1.9.3

# Django Rest Framework
# -------------------------------------
djangorestframework==3.3.2
django_filter<=0.11.0  # Do not upgrade until django 1.8
Markdown>=2.3.1,<2.5   # to fix conflict with mkdocs

和需求/开发。

代码语言:javascript
复制
-r common.txt

# Documentation
# -------------------------------------
mkdocs==0.15.2
# pygraphviz==1.3rc2
isort==4.2.2

# Debugging
# -------------------------------------
django-debug-toolbar==1.4
ipython==4.1.1
ipdb==0.8.1

# Testing
# -------------------------------------
mock==1.3.0
factory_boy==2.6.0
flake8==2.5.2
pytest==2.8.7
pytest-django==2.9.1
pytest-flakes==1.0.1
pytest-mock==0.10.1
pytest-pythonpath==0.7
coverage==4.0.3
freezegun==0.3.6
pytest-capturelog==0.7

# Versioning
# -------------------------------------
bumpversion==0.5.3

和要求/生产。

代码语言:javascript
复制
# Pro-tip: Try not to put anything here. There should be no dependency in
#   production that isn't in development.
-r common.txt

# WSGI Handler
# -------------------------------------
gunicorn==19.4.5

# Caching
# -------------------------------------
django-redis==4.3.0
hiredis==0.2.0

# S3 storgage
# -------------------------------------
# boto==2.39.0
# django-storages-redux==1.3.2

# Logging
# -------------------------------------
newrelic==2.60.0.46

在运行$ python3 manage.py makemigrations时进行需求安装后,出现以下错误。

代码语言:javascript
复制
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 18, in setup
    from django.utils.log import configure_logging
  File "/usr/local/lib/python3.5/dist-packages/django/utils/log.py", line 13, in <module>
    from django.views.debug import ExceptionReporter, get_exception_reporter_filter
  File "/usr/local/lib/python3.5/dist-packages/django/views/debug.py", line 10, in <module>
    from django.http import (HttpResponse, HttpResponseServerError,
  File "/usr/local/lib/python3.5/dist-packages/django/http/__init__.py", line 4, in <module>
    from django.http.response import (
  File "/usr/local/lib/python3.5/dist-packages/django/http/response.py", line 13, in <module>
    from django.core.serializers.json import DjangoJSONEncoder
  File "/usr/local/lib/python3.5/dist-packages/django/core/serializers/__init__.py", line 23, in <module>
    from django.core.serializers.base import SerializerDoesNotExist
  File "/usr/local/lib/python3.5/dist-packages/django/core/serializers/base.py", line 6, in <module>
    from django.db import models
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/__init__.py", line 6, in <module>
    from django.db.models.query import Q, QuerySet, Prefetch  # NOQA
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/query.py", line 13, in <module>
    from django.db.models.fields import AutoField, Empty, FieldDoesNotExist
  File "/usr/local/lib/python3.5/dist-packages/django/db/models/fields/__init__.py", line 18, in <module>
    from django import forms
  File "/usr/local/lib/python3.5/dist-packages/django/forms/__init__.py", line 6, in <module>
    from django.forms.fields import *  # NOQA
  File "/usr/local/lib/python3.5/dist-packages/django/forms/fields.py", line 18, in <module>
    from django.forms.utils import from_current_timezone, to_current_timezone
  File "/usr/local/lib/python3.5/dist-packages/django/forms/utils.py", line 15, in <module>
    from django.utils.html import format_html, format_html_join, escape
  File "/usr/local/lib/python3.5/dist-packages/django/utils/html.py", line 16, in <module>
    from .html_parser import HTMLParser, HTMLParseError
  File "/usr/local/lib/python3.5/dist-packages/django/utils/html_parser.py", line 12, in <module>
    HTMLParseError = _html_parser.HTMLParseError
AttributeError: module 'html.parser' has no attribute 'HTMLParseError'

尝试过的参考资料:

AttributeError:模块“html.parser”没有属性“HTMLParseError” https://code.djangoproject.com/ticket/23763

EN

回答 1

Stack Overflow用户

发布于 2017-08-14 07:55:45

你有两个机会:

  1. 使用python 3.4
  2. 将项目更新为Django 1.8

使用python 3.4

如果您正在使用Ubuntu,可以使用以下指令安装python3.4- https://askubuntu.com/questions/802279/how-to-install-python-3-4-5-from-apt

然后,您可以使用python3.4创建虚拟环境。

代码语言:javascript
复制
$ virtualenv .env -p /usr/bin/python3.4
$ source .env/bin/activate

将项目更新为Django 1.8

这是更困难但更好的方式,因为你会得到较少的bug,获得安全补丁,你可以使用新的功能。

这里你可以读到更多关于什么是新的以及如何升级你的项目。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45669256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档