Django tutorial customize admin template

I am working on the official Django tutorial. At the end of part two , they tweak the admin template a bit (by changing the header text). I think I did everything right, but apparently I haven't, because the admin site looks exactly the same after running syncdb and restarting the server. My project directory (excluding the virtualenv part) looks like this:

mysite
├── manage.py
├── mysite
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── settings.py
│   ├── settings.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── polls
│   ├── admin.py
│   ├── admin.pyc
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── tests.py
│   └── views.py
└── templates
    └── admin
        └── base_site.html

      

In settings.py I have these lines added so that the project uses the template in templates / admin:

import os
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))

      

later:

TEMPLATE_DIRS = (os.path.join(PROJECT_PATH, 'templates'),)

      

I tried several combinations of slash and variation when assigning value PROJECT_PATH

and TEMPLATE_DIRS

, but didn't get anything to work. Every time I checked that it actually created the filepath line (with a simple print operation).

To see what's going on, I edited the original Django base_site.html in my admin folder and changed my site, so he's obviously still using that. I have read several SO posts and I have no idea what to do next.

Oh, and if applicable: Python 2.7.3 and Django 1.4.3

+3


source to share


1 answer


The first thing I'll try is deleting your * .pyc files, which they often contain outdated information that can sometimes cause problems.

If it doesn't, I would double check yours PROJECT_PATH

, which I believe is the problem here.

dirname

gets the directory. so if that line is in settings.py, it will return the /path/to/inner/mysite

one inside the main mysite, and since mysite

there is no directory in your inner one templates

, it won't work.

what you need to do this.



PROJECT_PATH = os.path.realpath(os.path.dirname(os.path.dirname(__file__))) 

      

Which will return the outer path mysite

for you, combined with templates, it will return the correct path for you.

Then everything should work.

+4


source







All Articles