Maksat Yalkabov
Maksat Yalkabov

Reputation: 558

After installing app TemplateDoesNotExist error

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.

Inside django-myapp I copied the myapp to this folder and created all needed files for making python package.

And I ran python setup.py sdist. Until now everything is ok.

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.

My admin page works, and then I checked /env/alis5/lib/python3.4/site-packages/myapp/ there is no templates directory in it.

What is the problem. I followed django tutorial: https://docs.djangoproject.com/en/1.7/intro/reusable-apps/

here is my MANIFEST.in:

include LICENSE
include README.rst
recursive-include polls/static *
recursive-include polls/templates *
recursive-include docs *     

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='[email protected]',
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',
],
)

Upvotes: 0

Views: 420

Answers (2)

markwalker_
markwalker_

Reputation: 12859

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.

Create myapp/MANIFEST.in and inside it add recursive-include myapp/templates *

That should ensure that python setup.py sdist creates the package with your templates directory recursively.

edit

Ok, so I've just tested this on a project of mine.

- proj
  - setup.py
  - MANIFEST.in
  - injurytracker
    - init.py
    - templates
    - etc

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.

As you've mentioned include_package_data, setting that either way, doesn't effect the template directory inclusion.

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.*"]),

For me that picks out all my python modules & files that I expect, migrations included.

Upvotes: 1

Ihor Pomaranskyy
Ihor Pomaranskyy

Reputation: 5621

Do you have this in your settings.py?

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader', # <--
)

Upvotes: 0

Related Questions