没有名为“ LoginForm.LoginForm”的模块

时间:2019-11-07 12:07:51

标签: python django

我正在创建Django应用程序,并且遇到了这个问题,请您帮我解决一下。

这是错误:

  

回溯(最近一次通话最近):文件“ manage.py”,第21行,在          main()在main中的文件“ manage.py”,第17行       execute_from_command_line(sys.argv)

     

文件   “ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ core \ management__init __。py”,   第381行,在execute_from_command_line中       utility.execute()文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ core \ management__init __。py”,   行375,在执行       self.fetch_command(子命令).run_from_argv(self.argv)文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ core \ management \ base。 py”,   第336行,位于run_from_argv中       connections.close_all()文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ db \ utils.py”,   第219行,在close_all中       自我别名:文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ db \ utils.py”,   第213行,位于 it       返回iter(self.databases)文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ utils \ functional.py”,   第80行,获取       res =实例。 dict [self.name] = self.func(instance)文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site -packages \ django \ db \ utils.py”,   数据库中的第147行       self._databases = settings.DATABASES文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ conf__init __。py”,   第79行,位于 getattr       self._setup(name)文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ conf__init __。py”,   _setup中的第66行       self._wrapped =设置(settings_module)文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ site-packages \ django \ conf__init __。py”,   第157行,在 init       mod = importlib.import_module(self.SETTINGS_MODULE)文件“ C:\ Users \ vaidehi.shejwalkar \ AppData \ Local \ Programs \ Python \ Python38-32 \ lib \ importlib__init __。py”,   import_module中的第127行       在_gcd_import文件中,返回_bootstrap._gcd_import(name [level:],程序包,级别)文件“”,第1014行   _find_and_load文件中的第991行“”   “”,第961行,在_find_and_load_unlocked中   在第219行的文件“”中   _gcd_import文件“”的第991行的_call_with_frames_removed文件“”的第1014行,   在_find_and_load文件“”的第961行中   _find_and_load_unlocked文件“”,第219行,在_call_with_frames_removed文件“”中,第1014行,在_gcd_import文件“”中,第991行,在_find_and_load文件“”中,行973,在_find_and_load_unlocked中   ModuleNotFoundError:没有名为“ LoginForm.LoginForm”的模块

这是我的代码中的内容:

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 = 'q&jl$az$6ze8ukg!_cl^&e6-3^a^a%j2m!1po(9y-_%ho)39*6'

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

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'LoginForm.LoginForm.loginapp', // This is my app
    '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 = 'LoginForm.LoginForm.urls.py'

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 = 'LoginForm.LoginForm.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/'

url.py

from django.contrib import admin
from django.conf.urls import url, include
from django.contrib.auth.views import LoginView, LogoutView
from LoginForm.LoginForm.loginapp import views as core_views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^login/', include(LoginView.as_view()), {'template_name': 'login.html'}, name='login'),
    url(r'^sign_in/', include(core_views.signup), name='sign-up'),
    url(r'^logout/$', include(LogoutView.as_view()), {'template_name': 'logout.html'}, name='logout')
]

我的文件夹结构是:

LoginForm/  
 -LoginForm/  
    -loginapp/  
        -__init__.py  
        - admin.py  
        - apps.py  
        - models.py  
        - urls.py  
        - views.py  
     -Templates/  
        - base.html  
        - login.html  
        - sign_in.html  
        - logout.html  
        - home.html  
     -__init_.py  
     - apps.py  
     - settings.py  
     - urls.py 
     - wsgi.py  
 -manage.py  
 -__init__.py  

1 个答案:

答案 0 :(得分:0)

如果您的存储库如下:

project/
- settings.py
- urls.py
- other...
LoginForm/
- views.py
- models.py
- apps.py
- other...
manage.py

您应该有类似的东西:

INSTALLED_APPS = [
    'LoginForm.apps.loginapp', #So: <directory_name>/apps(corresponding to apps.py)/<Class name in the file>
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

希望它会为您提供帮助。