简体   繁体   English

Django-admin 命令错误 无法启动项目

[英]Django-admin command error Unable to start project

I am trying to start a project in a virtual environment using the django-admin command.我正在尝试使用 django-admin 命令在虚拟环境中启动一个项目。

pip freeze output: django==2.0.7 (part of the tutorial same happens w/ update package) pytz==2021.3 pip freeze output: django==2.0.7 (教程的一部分与更新包相同)pytz==2021.3

The error I get for django-admin check is我得到的 django-admin 检查错误是

Traceback (most recent call last):
  File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\Scripts\django-admin.exe\__main__.py", line 7, in <module>
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\__init__.py", line 425, in execute_from_command_line
    utility.execute()
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\__init__.py", line 419, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 373, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 417, in execute
    output = self.handle(*args, **options)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\commands\check.py", line 63, in handle
    self.check(
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 438, in check
    all_issues = checks.run_checks(
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\checks\registry.py", line 77, in run_checks    new_errors = check(app_configs=app_configs, databases=databases)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\core\checks\templates.py", line 29, in check_string_if_invalid_is_string
    for conf in settings.TEMPLATES:
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\conf\__init__.py", line 84, in __getattr__
    self._setup(name)
  File "C:\Users\%CurrentUser%\Documents\Dev\Django\lib\site-packages\django\conf\__init__.py", line 65, in _setup
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting TEMPLATES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

This just started after I had deleted my old project to start again using a comprehensive tutorial.这只是在我删除旧项目以使用综合教程重新开始之后才开始的。 I have tried deleting the virtualenv via clearing the \dev\django\ folder, and restarting.我尝试通过清除 \dev\django\ 文件夹并重新启动来删除 virtualenv。

I've seen other questions answered by editing the settings.py or manage.py file, but I don't have those at this stage.我已经看到通过编辑 settings.py 或 manage.py 文件回答了其他问题,但在这个阶段我没有这些问题。

Thanks.谢谢。

Update#1: Tried repairing python installs, and doing the same thing on another user.更新#1:尝试修复 python 安装,并对另一个用户执行相同的操作。 Still get the error.仍然得到错误。 I have noticed that launching the django-admin.py and.exe only difference is that the.exe goes through runpy.py first我注意到启动 django-admin.py 和 .exe 唯一的区别是 .exe 先通过 runpy.py

I made a mistake with the errors this is the error for django-admin startproject我犯了一个错误,这是 django-admin startproject 的错误

raceback (most recent call last):
  File "C:\Program Files\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\users\liam\documents\dev\Django\Scripts\django-admin.exe\__main__.py", line 7, in <module>
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
    utility.execute()
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\__init__.py", line 365, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\base.py", line 335, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\commands\startproject.py", line 20, in handle
    super().handle('project', project_name, target, **options)
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\management\templates.py", line 117, in handle
    django.setup()
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\__init__.py", line 16, in setup
    from django.urls import set_script_prefix
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\urls\__init__.py", line 1, in <module>
    from .base import (
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\urls\base.py", line 8, in <module>
    from .exceptions import NoReverseMatch, Resolver404
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\urls\exceptions.py", line 1, in <module>
    from django.http import Http404
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\http\__init__.py", line 5, in <module>
    from django.http.response import (
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\http\response.py", line 13, in <module>
    from django.core.serializers.json import DjangoJSONEncoder
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\serializers\__init__.py", line 23, in <module>
    from django.core.serializers.base import SerializerDoesNotExist
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\core\serializers\base.py", line 6, in <module>
    from django.db import models
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\__init__.py", line 3, in <module>
    from django.db.models.aggregates import *  # NOQA
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\aggregates.py", line 5, in <module>
    from django.db.models.expressions import Case, Func, Star, When
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\expressions.py", line 486, in <module>
    class TemporalSubtraction(CombinedExpression):
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\expressions.py", line 487, in TemporalSubtraction
    output_field = fields.DurationField()
  File "C:\Users\Liam\Documents\Dev\Django\lib\site-packages\django\db\models\fields\__init__.py", line 155, in __init__
    if isinstance(choices, collections.Iterator):
AttributeError: module 'collections' has no attribute 'Iterator'

Update#2 I updated to Django 3.0.0 Pip freeze output:更新#2 我更新到 Django 3.0.0 Pip 冻结 output:

asgiref==3.4.1
Django==3.0
pytz==2021.3
sqlparse==0.4.2

It works I can use the django-admin startproject.它有效,我可以使用 django-admin startproject。 I'm still weirded out that it worked with 2.0.7, and didn't work before with an updated package.我仍然很奇怪它可以与 2.0.7 一起使用,并且之前无法与更新的 package 一起使用。

looks like you on the python shell are you sure you on the cmd if not try cmd看起来像你在 python shell 如果不尝试 cmd 你确定你在 cmd 上

In you settings.py file there should be a variable called TEMPLATES在您的settings.py文件中应该有一个名为TEMPLATES的变量

When starting a fresh project it should look something like this:开始一个新项目时,它应该如下所示:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR,'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                 'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

From the error message you have shown us, im guessing this may be missing or misconfigured somehow.从您向我们展示的错误消息中,我猜这可能会丢失或以某种方式错误配置。

Try a different method of creating your project and see if that works?尝试另一种创建项目的方法,看看是否可行?

python -m django <command>

I have also double checked and youre using a really old version of django and i dont recommend.我还仔细检查过,您使用的是真正旧版本的 django,我不推荐。

Perhaps try upgrading to a later version of django and retry the original command aswell?也许尝试升级到更高版本的 django 并重试原始命令?

I have trouble somethink like you.. And i resolve by using this command:我遇到了像你这样的问题。我使用以下命令解决:

python -m pip install -U Django python -m pip 安装 -U Django

this is mean we cant upgrade your our jdango version..这意味着我们无法升级您的 jdango 版本..

And you cant try aganin to make new project with command:而且您不能尝试再次使用命令创建新项目:

django-admin startproject yournameproject django-admin startproject yournameproject

goodluck祝你好运

django-admin startproject logisticontrading django-admin: The term 'django-admin' is not recognized as the name of a cmdlet, function, script file, or operable program. django-admin startproject logisticontrading django-admin:术语“django-admin”未被识别为 cmdlet、function、脚本文件的名称。 Check the spelling of the name, or if a检查名称的拼写,或者如果
path was included, verify that the path is correct and try again.路径已包含,请验证路径是否正确,然后重试。 At line:1 char:1在行:1 字符:1

  • django-admin startproject logisticontrading django-admin 开始项目物流交易
  •  + CategoryInfo: ObjectNotFound: (django-admin:String) [], CommandNotFoun dException + FullyQualifiedErrorId: CommandNotFoundException

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

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