如何解决OSError:[WinError 123] pycharm中的文件名,目录名称或卷标签语法不正确

时间:2019-07-19 08:47:00

标签: python django

我是django的新手,我立即尝试编辑Web应用程序并运行服务器,我在终端上收到以下错误消息,请帮忙

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
main()
  File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
  File "C:\Users\W\PycharmProjects\manuproject\venv\lib\site- 
packages\django\core\manageme
nt\__init__.py", line 381, in execute_from_command_line
utility.execute()
  File "C:\Users\W\PycharmProjects\manuproject\venv\lib\site- 
packages\django\core\manageme
nt\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\W\PycharmProjects\manuproject\venv\lib\site- 
packages\django\core\manageme
nt\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
  File "C:\Users\W\AppData\Local\Programs\Python\Python37-32\lib\pathlib.py", 
line 1168, in stat

return self._accessor.stat(self)
OSError: [WinError 123] The filename, directory name, or volume label 
syntax is incorrect: '<frozen importlib._bootstrap>'

我希望在我的Web应用程序页面上输出Hello World

6 个答案:

答案 0 :(得分:1)

问题可能出在您的 .urls 中,特别是如果您遵循 Django 文档,复制代码片段而忘记更改 URL 详细信息以匹配您的应用程序设置。

例如,就我而言,我有这个:

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('crime_system/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

代替:

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('crime_system/', include('crime_system.urls')),
    path('admin/', admin.site.urls),
]

答案 1 :(得分:0)

由于我们尝试了所有调试过程,但无济于事,也许您需要删除此项目,然后按照本教程中的步骤启动一个新项目。 Django Tutorials

答案 2 :(得分:0)

这是settings.py文件

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'g_we0w^3!=y@rk40#m1+$luf!wc8d%x#*mekm#*z@g-vv^zowo'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.genres',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'djangoproject.urls'
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

WSGI_APPLICATION = 'djangoproject.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}


# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password- 
validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 
'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 
'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 
'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'

答案 3 :(得分:0)

我不确定这是否能解决您的原始问题,但是,至少,您应该检查指示Installed_apps的方式:

请参阅Django文档:https://docs.djangoproject.com/en/3.0/intro/tutorial02/#activating-models

INSTALLED_APPS = [
    'myapp.apps.MyappConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

养成编辑SECRET_KEY的习惯。

答案 4 :(得分:0)

我只是遇到了同样的问题。事实证明,在更新python之后,django-mptt和xlrd模块由于某种原因被卸载了。用pip重新安装它们,一切正常。

因此,您应该检查已安装的模块,并在必要时重新安装。

答案 5 :(得分:0)

检查您创建的 urls.py 文件是否在正确的位置...我遇到了类似的错误,错误,结果是我在应用程序目录之外创建了 urls.py。