【问题标题】:Problem with Django startproject: TypeError: '_sre.SRE_Match' object is not subscriptableDjango startproject 的问题:TypeError: '_sre.SRE_Match' object is not subscriptable
【发布时间】:2020-11-27 01:07:28
【问题描述】:

尝试运行

django-admin startproject mysite

出现这样的问题

Traceback (most recent call last):
  File "/Users/username/Desktop/test/venv/bin/django-admin", line 10, in <module>
    sys.exit(execute_from_command_line())
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/commands/startproject.py", line 20, in handle
    super().handle('project', project_name, target, **options)
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/core/management/templates.py", line 158, in handle
    template = Engine().from_string(content)
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/engine.py", line 136, in from_string
    return Template(template_code, engine=self)
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 155, in __init__
    self.nodelist = self.compile_nodelist()
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 193, in compile_nodelist
    return parser.parse()
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 447, in parse
    filter_expression = self.compile_filter(token.contents)
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 563, in compile_filter
    return FilterExpression(token, self)
  File "/Users/username/Desktop/test/venv/lib/python3.6/site-packages/django/template/base.py", line 638, in __init__

    var, constant = match['var'], match['constant']
TypeError: '_sre.SRE_Match' object is not subscriptable

我猜是版本有问题,但不知道具体是什么问题。

在 1.8.6 版本上一切正常,但是当我尝试使用时

from django.urls import path, include

我看到这个版本没有django.urls。

所以我想使用最新版本,如果你能帮助我,我将不胜感激!

Python 版本:

Python 3.6.0a4 

【问题讨论】:

  • 问题仍未解决,但在没有 venv 的情况下创建项目对我有帮助。尝试重新安装pycharm,但问题仍然存在。如果 smb 知道什么可以帮助我,我将不胜感激。

标签: python python-3.x django django-3.1


【解决方案1】:

看来您使用的是非官方版本的 django。 你好,先试试这个,不要删除任何东西让pip为你做:

pip install -U django

现在重新运行 startproject 命令行

【讨论】:

    猜你喜欢
    • 2018-02-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-16
    • 2020-11-02
    • 1970-01-01
    • 2022-08-13
    • 2021-11-17
    • 2018-01-23
    相关资源
    最近更新 更多