Django错误 - 没有模块命名 [英] Django error - no module named

查看:309
本文介绍了Django错误 - 没有模块命名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的相关目录结构(Windows 7,Python 2.7,virtualenv)

  -userProf 
- manage.py
- -UserProfile
- sampleapp_db
- urls.py
- views.py
- wsgi.py
- __init__.py
-
-libs
- - __init__.py
- --allauth
- - app_settings.py
- - models.py
- - tests .py
- - urls.py
- - utils.py
- - __init__.py
- -
- -account
- - - admin .py
- - - context_processors.py
- - - models.py
- - - urls.py
- - - __init__.py
- -socialaccount
- - - admin.py
- - - context_processors.py
- - - models.py
- - - urls.py
- - - views.py
- - - __init__.py
- - -
- -templates
- -account
- - - base.html
- - - 电子邮件。 html
-settings
- base_settings.py
- dev.py
- __init__.py
-
静态
-css

当我尝试运行此django应用程序时,我收到以下错误
错误:否模块命名的帐户



我已经阅读了SO上的其他帖子,指的是syspath是问题,或者appname与项目名称匹配



Django Shell没有命名设置的模块



。 ..的结果,我在base_settings.py文件中添加了以下语句

  import sys 
base = os.path.abspath(os.path.dirname(os.path.dirname(__ file__)))
base_parent = os.path.dirname(base)
sys.path.append(base)
sys.path.append(base_parent)
sys.path.append(os.path.join(base,'libs'))
sys.path.append(os.path.join( base,'libs','allauth','account'))

我验证了sys。路径是正确的在PyCharm中断并评估sys.path



我应该把它放在manage.py?



一些其他SO发布被称为无法导入模块,但是我可以启动python控制台并导入UserProfile.libs.allauth.account,而不会抛出任何异常!



我的base_setings.py具有以下相关部分

  INSTALLED_APPS = (
'UserProfile.libs.allauth.account',


解决方案

看起来像libs / allauth目录缺少文件;

  __ init__.py 

根据评论,最终的解决方案是更新manage.py文件中的sys.path文件



在settings.py文件中进行更改之前,不会看到settings.py中的更改,因为无法访问settings.py文件,直到对manage.py文件进行更改。 p>

Here is my relevant directory structure (Windows 7, Python 2.7, virtualenv)

-userProf
-   -   manage.py
    -   -UserProfile
            -   sampleapp_db
            -   urls.py
            -   views.py
            -   wsgi.py
            -   __init__.py
            -   
            -libs
            -   -   __init__.py
            -   -allauth
            -       -   app_settings.py
            -       -   models.py
            -       -   tests.py
            -       -   urls.py
            -       -   utils.py
            -       -   __init__.py
            -       -   
            -       -account
            -       -   -   admin.py
            -       -   -   context_processors.py
            -       -   -   models.py
            -       -   -   urls.py
            -       -   -   __init__.py
            -       -socialaccount
            -       -   -   admin.py
            -       -   -   context_processors.py
            -       -   -   models.py
            -       -   -   urls.py
            -       -   -   views.py
            -       -   -   __init__.py
            -       -   -   
            -       -templates
            -           -account
            -           -   -   base.html
            -           -   -   email.html
            -settings
            -       base_settings.py
            -       dev.py
            -       __init__.py
            -       
            -static
                -css

I get the following error when I try to run this django app Error: No module named account

I have read other posts on SO that refer to the syspath being the issue or that the appname matches the project name

Django Shell No module named settings

...as a result of this, I added the following statements in the base_settings.py file

import sys
base = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
base_parent = os.path.dirname(base)
sys.path.append(base)
sys.path.append(base_parent)
sys.path.append(os.path.join(base,'libs'))
sys.path.append(os.path.join(base,'libs','allauth','account'))

I verified that the sys.path is correct by putting a break in PyCharm and evaluating sys.path

Should I be putting this in manage.py?

Some other SO postings referred to not being able to import the module but I can launch the python console and import UserProfile.libs.allauth.account without any exceptions being thrown!

My base_setings.py has the following relevant section

INSTALLED_APPS = (
    'UserProfile.libs.allauth.account',
)

解决方案

looks like libs/allauth dir is missing the file;

__init__.py

Based on comments the final solution was to update the sys.path file in the manage.py file

Making the changes in the settings.py were not being seeing as it was not able to get to the settings.py file, until changes were made to the manage.py file.

这篇关于Django错误 - 没有模块命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆