现有Django项目中的语法错误

Dam*_*ski 1 python git django

我第一次安装了现有的Django项目,我遇到启动服务器的问题 python manage.py runserver

这就是我所做的

1.克隆回购,

2.创造一个虚拟环境

3.Pip install requirements.txt

4.生成访问令牌和密钥并放入secrets.sh.我settings.py和SECRET_KEY一样,secrets.sh并且我已经将secrets.sh添加到了.gitignore

5.更改settings.py如下:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'USER': 'name',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '',
    }
}
Run Code Online (Sandbox Code Playgroud)

我无法在python manage.py migrate下面运行结果:

(tag_gen) local_user@local_user:~/Repo/tag_gen/generator$ python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x7febe4712488>
Traceback (most recent call last):
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/local_user/Repo/tag_gen/generator/generator/urls.py", line 23, in <module>
    url(r'^etg/', include('generatorApp.urls', namespace='generatorApp')),
  File "/home/local_user/Repo/tag_gen/tag_gen/local/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/local_user/Repo/tag_gen/generator/generatorApp/urls.py", line 3, in <module>
    from . import views
  File "/home/local_user/Repo/tag_gen/generator/generatorApp/views.py", line 170
    def view_index(request: WSGIRequest):
                          ^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)

想法?

cwa*_*ole 6

您尝试运行的项目是使用Python≥3.5,但您尝试在2.7中运行它.

语法(request: WSGIRequest):类型提示.它是在几年前推出,但仅被添加到较新版本的Python 3中.没有努力支持Python≤3.4.

您需要查看有关如何virtualenv使用足够高的Python版本创建指令的说明.这基于操作系统而发生变化,因此详细说明可能超出了这个问题的范围,但是已经有很多关于该主题的建议.