Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Django中导入自定义模块;没有名为自定义“U模块”的模块;错误_Python_Django_Path_Virtualenv_Wsgi - Fatal编程技术网

Python 在Django中导入自定义模块;没有名为自定义“U模块”的模块;错误

Python 在Django中导入自定义模块;没有名为自定义“U模块”的模块;错误,python,django,path,virtualenv,wsgi,Python,Django,Path,Virtualenv,Wsgi,我编写了一个简单的模块,需要将其导入到Django设置文件中 导入发生在库字典的以下部分: TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(BASE_DIR, 'templates'), #re-route the search for templates

我编写了一个简单的模块,需要将其导入到Django设置文件中

导入发生在
字典的以下部分:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, 'templates'),

            #re-route the search for templates into this custom template directory
            os.path.join(os.path.join(BASE_DIR, 'templates'), 'tshirt-theme'),

            #Uncomment the line below to restore the original Oscar template
            #OSCAR_MAIN_TEMPLATE_DIR,
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.i18n',
                'django.contrib.messages.context_processors.messages',

                'oscar.apps.search.context_processors.search_form',
                'oscar.apps.promotions.context_processors.promotions',
                'oscar.apps.checkout.context_processors.checkout',
                'oscar.apps.customer.notifications.context_processors.notifications',
                'oscar.core.context_processors.metadata',
            ],
            'libraries': {
                'promotion_tags': 'custom_oscar.templatetags.promotion_tags'
            }
        },
    },
]
问题是我出错了。这是:

残废模板图书馆/

指定的模板库无效。当你试图 加载“custom\u oscar.templatetags.promotion\u tags”:未命名模块 自定义\u oscar.templatetags.promotion\u标记

代码在我的本地机器上运行,但在我将其迁移到生产环境(Ubuntu 16.01)时失败

我的项目结构如下:

/var/www/vhosts/book/
  ...book-site
          custom_oscar
               templatetags
                    promotion_tags.py
          manage.py
          book
              settings.py
              wsgi.py
     ..
  ...book-env
          bin
起初我怀疑问题可能出在路径上,所以我检查了跟踪,似乎包含了正确的路径:

Python路径:

['/var/www/vhosts/book/book-site',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages',
 '/var/www/vhosts/book/book-env/lib/python3.5/site-packages']
谁能告诉我为什么会发生这种错误?我怎样才能修好它


另外,如果有帮助,我可以在手动激活virtualenv时从命令行成功导入此模块。

根据您的描述,我怀疑您的
wsgi.py
或您的生产wsgi引擎(这是?)设置。目录中是否有
\uuu init\uuuuuuuuuuuuuuuuuuuupy
文件?@SachinKukreja没有。我试着在制作端添加它们,这起到了作用。为什么我的本地机器上没有这些文件它就可以工作?根据你的描述,我怀疑是你的
wsgi.py
还是你的生产wsgi引擎(这是?)设置。目录中有
\uuuu init\uuuuuu.py
文件吗?@SachinKukreja没有。我试着在制作端添加它们,这起到了作用。为什么我的本地机器上没有这些文件它还能工作?