tags:

views:

107

answers:

1

I'm a beginner with Django and I'm having trouble installing django-basic-apps using pip.

If I do this...

$ cat requirements.txt 
git+git://github.com/nathanborror/django-basic-apps.git

$ pip install -r requirements.txt

I end up with lib/python2.6/site-packages/basic/blog that does NOT have a templates directory.

If I do this...

git clone http://github.com/nathanborror/django-basic-apps.git

I end up with a copy of basic/blog that DOES have a templates directory.

I suspect something about django-basic-apps or pip makes it not able to be installed via pip. I thought maybe reading django-basic-apps's setup.py would lead me to the answer, but I couldn't see it.

(I should add that if I install without using pip, I'm able to get django-basic-apps working just fine)

+4  A: 

When you use "pip" to install something, the package's setup.py is used to determine what packages to install. And this project's setup.py, if I'm reading it correctly, says "just install these Python packages inside the basic directory" — the setup.py makes absolutely no mention of any non-Python files it wants included in the install.

This might be deliberate on the developer's part, since it is something of a tradition for Django packages to not include templates — notoriously, even something so basic as the built-in django.contrib.auth comes without any templates and makes you build its little forms from the ground up each time! (Or, to cut and paste from examples elsewhere on the web.)

But if you yourself want the templates to be installed with this Python distribution, regardless of how the author has set things up, then just list the templates in the setup.py! First, add something like this to the setup.py file:

template_patterns = [
    'templates/*.html',
    'templates/*/*.html',
    'templates/*/*/*.html',
    ]

Then, add one last variable to the setup() call so that it ends like this:

...
packages=packages,
package_data=dict( (package_name, template_patterns)
                   for package_name in packages ))

This asserts to the setup() function that every package should be accompanied by data files that are found by searching for HTML files beneath each package's templates directory.

Try it out, and let me know if this works on your machine too!

Brandon Craig Rhodes
Thank you Brandon. It worked, but more importantly, I understand it better now. Thank you!
golliher
You're welcome! I should note, for future readers, that the above code is a bit brittle and only works for templates up to two directories deep inside of "templates.html"; a full-fledged example might `os.walk()` the whole tree and find all `.html` files however deep. Too bad that `package_data` patterns do not support the zsh(1) convention: `templates/**/*.html`
Brandon Craig Rhodes
Thanks Brandon, excellent answer. FWIW I highly doubt this is intentional; it would be unusual to include the templates in that location in the source repo if they weren't intended to be used with the app. Simple packaging fail is much more likely; I've filed a bug with the project to make sure the author is aware of this problem.
Carl Meyer