如何在django

时间:2017-08-14 07:16:28

标签: python django python-3.x django-rest-framework pip

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

  

来自django.utils.html import format_html,format_html_join,escape
    文件“/usr/local/lib/python3.5/dist-packages/django/utils/html.py”,第16行,中
      来自.html_parser导入HTMLParser,HTMLParseError
    文件“/usr/local/lib/python3.5/dist-packages/django/utils/html_parser.py”,第12行,中
      HTMLParseError = _html_parser.HTMLParseError
  AttributeError:module'html.parser'没有属性'HTMLParseError'

Python 3.5 django 1.7.7 使用pip3

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

我该怎么做: -

  • 将HTMLParser替换为另一个类似的如何??? OR

  • 降级python版本我试过这个但是它默认使用了lib - > /usr/lib/python3.5如何更改此路径

请帮忙。

我的需求文件要求/ common.txt就像这样

# 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

和requirements / development.txt

-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

和requirements / production.txt

# 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后的需求安装后,出现此错误。

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: module 'html.parser' has no attribute 'HTMLParseError' https://code.djangoproject.com/ticket/23763

1 个答案:

答案 0 :(得分:1)

您有2个机会:

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

    如果您使用的是Ubuntu,可以使用此指令安装python 3.4 - https://askubuntu.com/questions/802279/how-to-install-python-3-4-5-from-apt

    然后你可以使用python 3.4

    创建virtualenv
    import * as moment, { Moment } from 'moment';
    import { * as moment, Moment } from 'moment';
    import { * as moment, Moment as Moment } from 'moment';
    

    将您的项目更新为Django 1.8

    这是更困难但更好的方法,因为您将获得更少的错误,获得安全补丁并且您可以使用新功能。

    Here您可以详细了解新功能以及如何升级项目。