当前位置: 首页 > 知识库问答 >
问题:

现有Django项目中的语法错误

慕容雅珺
2023-03-14

我已经安装了现有的Django项目非常第一次,我有启动服务器的问题pythonmanage.pyrunserver

这就是我所做的

1.克隆回购协议,

2.创建虚拟环境

3.Pip安装要求.txt

4.生成访问令牌和密钥,并放入secrets.sh.我在settings.pysecrets.sh中有相同的SECRET_KEY,我已经将secrets.sh添加到. gitignore

5.更改设置.py如下:

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

我无法运行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

想法?

共有2个答案

鄢松
2023-03-14

1.检查您的python和django版本是否应与安装的要求兼容。如果您的python版本超过3。使用运行服务器

python3 manage.py runserver

如果python版本为2.7,则为

python manage.py runserver
燕青青
2023-03-14

您试图运行的项目正在使用Python≥ 3.5,但您正在尝试在2.7中运行它。

语法(请求:WSGIRequest):是一个类型提示。它是在几年前引入的,但只添加到较新版本的Python3中。没有做出任何努力来支持Python≤ 3.4.

您需要查找有关如何使用足够高的Python版本创建Virtualenv的说明。这种变化基于操作系统,所以详细的说明可能超出了这个问题的范围,但是已经有很多关于这个主题的建议了。

 类似资料:
  • 本文向大家介绍django项目中新增app的2种实现方法,包括了django项目中新增app的2种实现方法的使用技巧和注意事项,需要的朋友参考一下 1.在pycharm的工具栏找到 Tools,点击之后会有“Run manage.py task”选项,点击它之后,在pycharm下面会出现一个输入界面,在里面输入 “startapp appName(你的App名称)” 回车之后就可以在工程下面看到

  • 我想将我现有的Gradle项目导入到我已经从SVN签出的Eclipse本地目录中。项目包含两个分支上的代码。我尝试使用导入现有gradle项目选项,但导入后,我得到没有构建路径错误,当我试图使用Eclipse(请参阅调用层次结构和其他功能)。我不一定想从eclipse构建项目,我只是想在eclipse中编辑代码,并希望更改反映在本地,从那里我可以手动构建。 你能告诉我一些链接或提供实现这一点的步骤

  • 在Bluehost cPanel中上传后,我的Laravel项目中出现以下错误。但在本地服务器中没有错误。 解析错误:语法错误,意外的const(T_CONST),预期变量(T_VARIABLE) 这是密码 我的本地服务器PHP版本是7.2。0 Bluehost PHP版本是7.0.0 这是与PHP版本相关的问题吗? 如何解决这个问题?

  • 我试图查看Eclipse(版本Mars.2)中提供的springboot初学者项目,但遇到了错误。 这就是我所做的: 选择spring boot会给我两个新项目: ` 谷歌搜索此错误导致我进入maven存储库,所以我导入ch.qos.logback 再次运行(运行作为…- ``` 谢谢你的帮助!

  • 我从repository获得了项目,按照设置说明,我尝试在eclipse中创建一个项目,并将该位置指向我从repository下载代码的地方。然后当我点击finish时,我得到了一个错误声明 “未满足一个或多个约束。无法安装project facet Java 1.6。此project facet的某些版本已安装。无法安装project facet动态Web模块3.0。此project facet