简体   繁体   English

django-admin startproject 给出 SyntaxError

[英]django-admin startproject gives SyntaxError

I tried to start a new project with django 4.0 After installing Django in environment folder (Anaconda/envs/taskman) I created a new folder somewhere in my e: drive and by using windows command line created a new folder Django_site.我尝试使用 django 4.0 开始一个新项目 在环境文件夹(Anaconda/envs/taskman)中安装 Django 后,我在我的 e: 驱动器的某处创建了一个新文件夹,并使用 Z0F4137ED1502B5045CD6083AA258 命令行创建了一个新文件夹。 Then from this folder I typed in command line prompt: django-admin startproject lifetool and got the following:然后从这个文件夹中输入命令行提示符:django-admin startproject lifetool 并得到以下信息:

    (taskman) E:\Projects\Django_site>django-admin startproject lifetool
    Traceback (most recent call last):
    File "E:\Programs\Anaconda\envs\taskman\Scripts\django-admin- 
    script.py", line 5, in <module>
    from django.core.management import execute_from_command_line
    File "E:\Programs\Anaconda\envs\taskman\lib\site- 
    packages\django\core\management\__init__.py", line 16, in <module>
    from django.core.management.base import (
    File "E:\Programs\Anaconda\envs\taskman\lib\site- 
    packages\django\core\management\base.py", line 13, in <module>
    from django.core import checks
    File "E:\Programs\Anaconda\envs\taskman\lib\site- 
    packages\django\core\checks\__init__.py", line 18, in <module>
    import django.core.checks.translation  # NOQA isort:skip
    File "E:\Programs\Anaconda\envs\taskman\lib\site- 
    packages\django\core\checks\translation.py", line 3, in <module>
    from django.utils.translation.trans_real import language_code_re
    File "E:\Programs\Anaconda\envs\taskman\lib\site- 
    packages\django\utils\translation\trans_real.py", line 485
    while (i := lang_code.rfind('-', 0, i)) > -1:
         ^
   SyntaxError: invalid syntax

What is wrong?怎么了? Do I need to correct invalid syntax in installed Django package?我是否需要更正已安装的 Django package 中的无效语法? Help me to clarify the issue帮我澄清问题

The "walrus operator" := was introduced in Python 3.8 . “海象运算符” := 在 Python 3.8 中引入 You must be using an earlier version of Python.您必须使用早期版本的 Python。

Since Django 4.0 only officially supports Python 3.8, 3.9, and 3.10 , you'll either need to use a newer version of Python or an older version of Django. Since Django 4.0 only officially supports Python 3.8, 3.9, and 3.10 , you'll either need to use a newer version of Python or an older version of Django.

proper commands are:正确的命令是:

python -m django --version

Django 4.0 Django 4.0

django-admin startproject lifetool

the project structure will be项目结构将是

lifetool/
manage.py
lifetool/
    __init__.py
    settings.py
    urls.py
    asgi.py
    wsgi.py

python manage.py runserver

BOOM server is running: BOOM 服务器正在运行:

Django version 4.0, using settings 'lifetool.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

I don´t know if you did it this way, but try to install django by the command python -m pip install Django More info here我不知道你是否这样做,但尝试通过命令python -m pip install Django更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM