Question

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.)

Was it helpful?

Solution

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!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top