安装应用程序TemplateDoesNotExist错误后 [英] After installing app TemplateDoesNotExist error
问题描述
在virtualenv中,默认为python3:
首先,我从项目中删除了我的应用 myapp .然后,我在下一个django项目主目录下创建了一个名为 django-myapp 的新文件夹.
In virtualenv defaulting python3:
First I removed my app myapp from project. And I created a new folder called django-myapp next main django project directory.
在 django-myapp 内部,我将 myapp 复制到了该文件夹,并创建了用于制作python软件包的所有必需文件.
Inside django-myapp I copied the myapp to this folder and created all needed files for making python package.
然后我运行了 python setup.py sdist
.到现在为止一切正常.
And I ran python setup.py sdist
. Until now everything is ok.
我的模板和CSS文件包含在 django-myapp-0.1.tar.gz 文件中.但是,当我使用 pip install django-myapp/dist/django-myapp-0.1.tar.gz
安装此应用程序时,该应用程序即已安装.但是,当我运行服务器并转到主页 TemplateDoesNotExist 时,会发生错误.
My template and css files are included in django-myapp-0.1.tar.gz file. But when I installed this app with pip install django-myapp/dist/django-myapp-0.1.tar.gz
, the app is installed. But when I run server and go to main page TemplateDoesNotExist error happens.
我的管理页面有效,然后我检查了/env/alis5/lib/python3.4/site-packages/myapp/,其中没有 templates 目录
My admin page works, and then I checked /env/alis5/lib/python3.4/site-packages/myapp/ there is no templates directory in it.
出了什么问题.我遵循了django教程: https://docs.djangoproject.com/zh/1.7/intro/reusable-apps/
What is the problem. I followed django tutorial: https://docs.djangoproject.com/en/1.7/intro/reusable-apps/
这是我的MANIFEST.in:
here is my MANIFEST.in:
include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
recursive-include docs *
这也是我的setup.py:
and here is also my setup.py:
setup(
name='django-polls',
version='0.1',
packages=['polls'],
include_package_date=True,
license='BSD License', # example license
description='A simple Django app to conduct Web-based polls.',
long_description=README,
url='http://www.example.com/',
author='Maksat Yalkabov',
author_email='yalkabovmaksat@gmail.com',
classifiers=[
'Environment :: Web Environment',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License', # example license
'Operating System :: OS Independent',
'Programming Language :: Python',
# Replace these appropriately if you are stuck on Python 2.
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.2',
'Programming Language :: Python :: 3.3',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
],
)
推荐答案
您说您遵循了本教程,但是我不得不问,您是否创建了清单文件?您没有提到它,默认情况下仅包含Python.
You said you followed the tutorial, but I have to ask, did you create the manifest file? You didn't mention it, and only Python is included by default.
在 myapp/MANIFEST.in
中创建 myapp/MANIFEST.
Create myapp/MANIFEST.in
and inside it add recursive-include myapp/templates *
那应该确保 python setup.py sdist
递归地使用模板目录创建该包.
That should ensure that python setup.py sdist
creates the package with your templates directory recursively.
修改
好,所以我刚刚在我的一个项目中对此进行了测试.
Ok, so I've just tested this on a project of mine.
- proj
- setup.py
- MANIFEST.in
- injurytracker
- init.py
- templates
- etc
在 setup.py
中,我有 packages = ['injurytracker'],
包括我的包裹,并且在 MANIFEST.in
中我已经有了 recursive-include traimturetracker/templates *
,当我检查dist.gz时,我已经包含了我的模板.
In setup.py
I've got packages=['injurytracker'],
to include my package, and in MANIFEST.in
I've got recursive-include injurytracker/templates *
And when I check the dist.gz I've got my templates included.
就像您提到的 include_package_data
一样,以任何一种方式设置都不会影响模板目录的包含.
As you've mentioned include_package_data
, setting that either way, doesn't effect the template directory inclusion.
在您的 setup.py
中,还从setuptools导入 find_packages
,然后在您的设置方法中添加如下所示的东西:
In your setup.py
also import find_packages
from setuptools, and in your setup method add somthing like this;
packages=find_packages(exclude=["project", "project.*"]),
对于我来说,我选择了所有的python模块&我期望的文件,包括迁移.
For me that picks out all my python modules & files that I expect, migrations included.
这篇关于安装应用程序TemplateDoesNotExist错误后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!