【问题标题】:manage.py runserver invalid syntaxmanage.py runserver 语法无效
【发布时间】:2019-10-20 21:40:46
【问题描述】:

更新

我无意中编辑了 manage.py 文件。

manage.py文件中的代码需要是-

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project1.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    main()

然后在 CMD (Windows Key + R) 中输入 -

C:\Users\HP\django_project1\django_project1>cd C:\Users\HP\django_project1

原始问题 我正在尝试运行命令python manage.py runserver$python manage.py runserver$ python manage.py runserver,但不断出现错误。

我尝试过python manage.py runservermanage.py runserverpython3 manage.py runserver

Microsoft Windows [Version 10.0.17134.165]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\HP>cd C:\Users\HP

C:\Users\HP>cd C:Users\HP\django_project
The system cannot find the path specified.

C:\Users\HP>cd C:\Users\HP\django_project

C:\Users\HP\django_project>python manage.py runserver
  File "manage.py", line 3
    python3 manage.py runserver
                 ^
SyntaxError: invalid syntax

C:\Users\HP\django_project>manage.py runserver
  File "C:\Users\HP\django_project\manage.py", line 3
    python3 manage.py runserver
                 ^
SyntaxError: invalid syntax

C:\Users\HP\django_project>python3 manage.py runserver
'python3' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\HP\django_project>python manage.py runserver
  File "manage.py", line 3
    python3 manage.py runserver
                 ^
SyntaxError: invalid syntax


C:\Users\HP\django_project>dir /s >listmyfolder.txt



 Volume in drive C is Windows
 Volume Serial Number is D84A-5EE6

 Directory of C:\Users\HP\django_project

10/20/2019  10:15 PM    <DIR>          .
10/20/2019  10:15 PM    <DIR>          ..
10/19/2019  05:50 PM    <DIR>          django_project
10/20/2019  10:15 PM               113 listmyfolder.txt
10/20/2019  08:23 PM                53 manage.py
               2 File(s)            166 bytes

这里是 django_project 的内容 -

 Directory of C:\Users\HP\django_project\django_project

10/19/2019  05:50 PM    <DIR>          .
10/19/2019  05:50 PM    <DIR>          ..
10/19/2019  05:50 PM             3,232 settings.py
10/19/2019  05:50 PM               777 urls.py
10/19/2019  05:50 PM               421 wsgi.py
10/19/2019  05:50 PM                 0 __init__.py
               4 File(s)          4,430 bytes

     Total Files Listed:
               6 File(s)          4,596 bytes
               5 Dir(s)   7,345,328,128 bytes free

【问题讨论】:

    标签: python django python-3.x


    【解决方案1】:

    由于某种原因,您似乎编辑了 manage.py 文件,使其包含文本“python3 manage.py runserver”。我不知道你为什么这样做,但你应该删除它。

    【讨论】:

    • 谢谢,我对 Sublime 没有经验,毫无意义地做出了改变。
    猜你喜欢
    • 2018-06-01
    • 1970-01-01
    • 2017-05-05
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    相关资源
    最近更新 更多