Now I'm developing a feedback application,
So, the admin must see messages from users, filter them(read/unread) and mark them as important.
I have already done all the functionality I need, but i cannot customize my headers.
For example.
There is a default header in change list(see the screenshot, this header is selected),
How can I delete these headers or customize them?
Great thanks in advance.
Actually, the answer from #mayankTUM is not correct. It does not follow the django design philosophies and should not be implemented (#mayankTUM himself mentions one of the problems of his solution however there are many, many more)!
Basically, what you need to do can be done by overriding the admin templates. Because there are some problems with that (I will explain later), here's exactly what
I did to solve your requirement:
Created a directory named admin in my templates folder.
Copied there the change_list.html template from <django>\contrib\admin\templates\admin\change_list.html.
Added the following to the end of the new change_list.html: {% block content_title %}Hello world!{% endblock %}
Now, instead of "Select ... to change" it will print "Hello world!"
I have to notice that copying the whole change_list.html is not DRY - it'd be much better if I just created the file, made it extend from admin/change_list.html and add the content_title. However this is not working and will lead to infinite recursion (please check this bug report https://code.djangoproject.com/ticket/15053 ) -- this is the problem to which I was referring before. A better solution that copying over the whole template is discussed in the following questions:
Django: Overriding AND extending an app template
and
How to override and extend basic Django admin templates? and
django override admin template
PS: My TEMPLATE_DIRS and TEMPLATE_LOADERS project settings are these:
TEMPLATE_DIRS = (
PROJECT_PATH.child('templates'),
)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
Related
Just curious, especially since Django is all about the DRY principle, why doesn't it include urls.py with creation of new app?
Maybe it's just my case(I'm relatively new to Django), but at least 90% of the time, I need to create a urls.py file, which seems quite repetitive to me. There are other actions while doing a web project/app that I've found repetitive, but the URLs seems fundamental to the structure, so don't see what the harm would be for it to be included with the new app creation.
Any thoughts, insights?
This is default startapp template behavior that Django team decided it is minimal ( not everyone would create urls.py in each app)
You can customize this behavior by providing your own app_template that suits your needs
From startapp documentation:
django-admin startapp --template=/Users/jezdez/Code/my_app_template myapp
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.
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.
The first thing I did was of course customizing forms, views and templates in site-packages. And then I learned that everything will be reset to default after upgrading the package.
So now I decided to create a new application "accounts" and make customizations there.
My question is which approach is better (haven't tried any, sorry)
First approach:
Set INCLUDE_REGISTER_URL = False
in accounts.views import RegistrationView and create MyRegistrationView (same thing with forms)
in accounts.urls include registration.backends.default.urls and create my own urlpattern for MyRegistrationView
create custom templates in templates/registration
put registration above django.contrib.admin in INSTALLED_APPS
Second approach:
in accounts.views import RegistrationView and create MyRegistrationView (same thing with forms)
Create complete replica of registration.backends.default.urls in accounts.urls with my new custom template names
put custom templates inside my accounts app
Or are there any better approaches? (probably are)
First of all, if you want to override almost every part of redux, wont it be better to use built-in django authentication and to extend it as you wish?
Yes, you are on the right way. You need to override those things you do not like by coping them to your project and then by changing the copy. Though it's will be a cleaner code if you place templates in templates/registration, views in views.py and etc, actually you can do in some other way you wish.
Usually I have the opposite problem, Django can't find the templates.
Lastly, I change a template of mine called custmber_view.html, but Django didn't notice the chagnes.
I tried flushing all caches, without success. In my dispair, I completely removed the template
hoping to see the familiar TemplateDoesNotExist exception.
To my surprise, Django keeps rendering the template! Although it is not found on the hard-drive.
Can someone suggest a solution to this mystery?
ARGH, legacy projects, I am doomed to fix them for ever. Somewise guy put the following in settings.py:
TEMPLATE_DIRS = (
os.path.join(project_dir, u'templates'),
u'/var/www/venv2.7/lib/python2.7/site-packages/backoffice/templates',
)
I feel like this now ...
So, conclusion, If you are working on a project which was not made as a Django App, always make sure you read the variable TEMPLATE_DIRS.
But for your colleagues future (and for better moral) always follow How to write reusable Django app