Django runserver 给了我语法错误

标签 django python-2.7 django-models

python manage.py runserver
Performing system checks...

Unhandled exception in thread started by <function wrapper at 0x03BBC1F0>
Traceback (most recent call last):

  File "C:\Python27\lib\site-packages\django\utils\autoreload.py", line 227, in wrapper
    fn(*args, **kwargs)

File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)

  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,

File "C:\Python27\lib\site-packages\django\core\management\base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)

File "C:\Python27\lib\site-packages\django\core\checks\registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)

  File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 16, in check_url_config
    return check_resolver(resolver)

  File "C:\Python27\lib\site-packages\django\core\checks\urls.py", line 26, in check_resolver
    return check_method()

File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 254, in check
    for pattern in self.url_patterns:

  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)

  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

  File "C:\Python27\lib\site-packages\django\utils\functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)

  File "C:\Python27\lib\site-packages\django\urls\resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)

  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)

  File "C:\Users\Kaidi\Desktop\CM2\CM\CM\urls.py", line 18, in <module>
    from mysite import views

  File "C:\Users\Kaidi\Desktop\CM2\CM\mysite\views.py", line 2, in <module>
    from rest_framework import viewsets, permissions, status

  File "C:\Python27\lib\site-packages\rest_framework\viewsets.py", line 26, in <module>
    from rest_framework import generics, mixins, views

  File "C:\Python27\lib\site-packages\rest_framework\generics.py", line 10, in <module>
    from rest_framework import mixins, views

  File "C:\Python27\lib\site-packages\rest_framework\views.py", line 98, in <module>
    class APIView(View):

  File "C:\Python27\lib\site-packages\rest_framework\views.py", line 103, in APIView
    authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSES

  File "C:\Python27\lib\site-packages\rest_framework\settings.py", line 220, in __getattr__
    val = perform_import(val, attr)

  File "C:\Python27\lib\site-packages\rest_framework\settings.py", line 165, in perform_import
    return [import_from_string(item, setting_name) for item in val]

  File "C:\Python27\lib\site-packages\rest_framework\settings.py", line 177, in import_from_string
    module = import_module(module_path)

  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)

  File "C:\Python27\lib\site-packages\rest_framework_jwt\authentication.py", line 1, in <module>
    import jwt
  File "C:\Python27\lib\site-packages\jwt\__init__.py", line 17, in <module>
    from .jwk import (

  File "C:\Python27\lib\site-packages\jwt\jwk.py", line 60
    def is_sign_key(self) -> bool:
                          ^

SyntaxError: invalid syntax

最佳答案

你好像安装了 JWT 包,它只兼容 Python 3.4+。 rest-framework-jwt 应用程序试图导入它,而不是与 2.7 兼容的 PyJWT。

使用 pip uninstall jwt 删除该安装.删除后,您将需要像这样安装 PyJWT:

pip install PyJWT

关于Django runserver 给了我语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43716699/

相关文章:

python - 在 model.save() 中处理竞争条件

Django "The view didn' t 返回一个 HttpResponse 对象。”

Django 标签在 block 标签中返回数组

python - 如何在 Matplotlib 中的图框外绘制矩形

python - 如果这个方法是错误的,那么为什么解释器只执行了一半呢?

python-2.7 - 如何在 Tensorflow 中增加变量?

django - 如何自动让syncdb添加列(不需要完全迁移)

django - 如何使用 1 个 django 项目管理多个网站

python - Django 。通过关闭钩子(Hook)上的模型访问数据库

python - Django SessionWizardView 不执行完成方法