Extend Django Admin Tools template - python

Is there a way I can override the brand block of django-admin-tools, which extends from Django's admin app?
If there is, how?
I tried placing base_site.html in one of the templates folders of my project, but Django is not picking it up, assumably because django-admin-tools has priority over the other templates because of the order of the apps in my settings. But if I change the order, django-admin-tools stops working as it's required to be at the top in my settings.

Related

how to break down the admin app in django.contrib.auth to understand its working

I have been working with django for nearly 3 months and have been customizingadmin templates only. If I wanted to add any elements like buttons or some charts I extend the base.html, and then serve the extending template with another view inside my app(say Blog). But I want to customize my admin as much as possible but don't know how to do it. I have read the docs and it just gives snippets.
So to summarize, I want to create the admin site for my own blog right from scratch to understand the admin app in the contrib package in more detail.

django registration redux ignoring changes in templates

I've been struggling with Django registration redux over the past two weeks. I'm using the templates that were provided in the documentation and I've made a couple of changes like adding crispy forms and changing the button and some other stuff but the problem is that none of these changes are being shown on http://127.0.0.1:8000/accounts/register or any other link.
I'm using Django registration redux 1.4, Django 1.8, python 2.7.10
Putting your customized templates in templates/registration (not register) should work.
At least if your TEMPLATES setting is correctly configured: https://docs.djangoproject.com/en/1.8/ref/templates/upgrading/
And you probably already checked this hint from the project's FAQ?
I want to use custom templates, but django keeps using the admin
templates instead of mine!
To fix this, make sure that in the INSTALLED_APPS of your settings.py
the entry for the registration app is placed above
django.contrib.admin.

Django: how do I redistribute a project/app that contains extendable HTML templates?

I am reading through the Django tutorial How to write reusable apps. I am trying to figure out how to package HTML base templates so that people who install my app (through pip) can extend them (e.g. with {% extends %}.) When I import a python module I don't have to know its location on the filesystem, but is that the case for Django templates?
(Side note: My project consists of plumbing that make it easier to write a specific type of app. So I have various abstract base classes [models, views, forms], template tags, URL configuration, and HTML templates that users can inherit from. It also contains customizations to Django Admin. Right now it is a project but I am trying to package it as an app because according to what I am reading, that seems to be the right way to package Django code, but maybe I should be doing it differently.)
Use a template dir structure like this:
awesome_app_name/
templates/
awesome_app_name/
base.html
cool_template.html
This allows someone to extend your templates with:
{% extends 'awesome_app_name/cool_template.html' %}
OR they could just swap it out with their own template like this:
my_app_name/
templates/
my_app_name/
my_template.html
awesome_app_name/
cool_template.html <-- this overloads your template with their own
This makes for very flexible templates in shared packages.
EDIT:
This works if you configure django with both a template directory for your project and the app_directories.Loader template loader. I believe this to be the configuration used by most:
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
os.path.join(PROJECT_DIR, 'templates'),
)
Template loading is then done in the following order:
Resolve template from project directory
Resolve template from app directories
Here's an example project that follows this structure: https://github.com/brutasse/django-password-reset

Django wrong precedence of templates?

It took me forever to find out why a template was not getting overridden, only to find that it seems Django simply does not use the correct precedence in overriding the templates.
The templates I'm trying to change are the ones for changing the user's password, which are loaded for the URL /accounts/password/change.
I have my modified templates in mysite/myapp/templates/registration; the system default templates are at /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admin/templates/registration. When templates are present in both these directories, Django uses the system (/Library) ones. Huh?
When I remove the templates in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/admin/templates/registration
, the correct ones (i.e. mine, in mysite/myapp/templates/registration) are loaded.
How to fix this issue? That is, how to make Django load my overridden templates without having the delete the original templates found in the /Library?
you have to create an admin directory inside the templates dir in which you set the templates you want to override
In order to override one or more of them, first create an admin directory in your project’s templates directory. This can be any of the directories you specified in TEMPLATE_DIRS.
Read the Django doc here

Django : How to structure template folder considering template tag includes?

I have my template folder with all html templates lieing together in the template folder with no directory structure as such.
I decided to arrange them on per app basis, but:
A template with template-tags belong to different apps.
Eg:
Login page(Login app) includes a banner that belongs to UserActivity [User activity app]. So, if I include the login template in login folder in templates, then it will be including stuff across other app's template folder.
How should I structure so that all that referred stays in 1 place organized ?
Feel free to ask for more info.. :)
Organizing your templates in subdirectories is definitely they way to go, but I am not sure if you can really reach the level of separation you are looking for.
If your apps depend on each other you'll always have includes and tags from other apps. So i'd put the templates to the app they belong to.
But maybe the docs about template loaders can help you clarify your structure.
For example the app_directories.Loader
Loads templates from Django apps on the filesystem. For each app in
INSTALLED_APPS, the loader looks for a templates subdirectory. If the
directory exists, Django looks for templates in there.
This means you can store templates with your individual apps. This
also makes it easy to distribute Django apps with default templates.
So you could put app-specific templates in in your app directories and keep your general templates (base.html, etc.) in the top level template dir of your project.

Categories

Resources