Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#23575 closed Cleanup/optimization (fixed)

Add a code example for custom AdminSite

Reported by: hernandocounty Owned by: Berker Peksag
Component: Documentation Version: 1.7
Severity: Normal Keywords: TEMPLATES_DIR
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

the current way listed did not work for me.

It would behoove the beautiful documentation of Django to make it a little more clear.

http://stackoverflow.com/questions/4938491/django-admin-change-header-django-administration-text

here is the link.

I would be delighted to help in this project.

thanks

Doug

Is there anything else I could do to help ?

If you tell me what info you need and don't treat me like I'm an idiot I would love to help.

Sorry Just had a lot of negative experiences trying to contribute to projects.

Change History (13)

comment:1 Changed 5 years ago by Tim Graham

You can read about contributing to our documentation. From your report, it's not clear where the error is in our docs.

comment:2 Changed 5 years ago by hernandocounty

Customizing your project’s templates

Create a templates directory in your project directory. Templates can live anywhere on your filesystem that Django can access. (Django runs as whatever user your server runs.) However, keeping your templates within the project is a good convention to follow.

Open your settings file (mysite/settings.py, remember) and add a TEMPLATE_DIRS setting:
mysite/settings.py

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]

TEMPLATE_DIRS is an iterable of filesystem directories to check when loading Django templates; it’s a search path.

Now create a directory called admin inside templates, and copy the template admin/base_site.html from within the default Django admin template directory in the source code of Django itself (django/contrib/admin/templates) into that directory.

this is what I tried along with these solutions also.

i tried these solutions from earlier versions

# TEMPLATE_DIRS = [os.path.join(BASE_DIR, '/home/<username>/dev/09292014/stocks_day1/templates/')]

TEMPLATE_DIRS = ('/home/<username>/dev/09292014/stocks_day1/templates',)

these i placed in settings.py after trying the method in the tutorial.

Thanks

Doug

comment:3 Changed 5 years ago by Tim Graham

Are you using the version of the tutorial that matches the version of Django you have installed? It's not clear to me what the problem is besides things "not working." Did you find your error? Without knowing that, I'm not sure how things should be clarified. See Getting Help if you need to help resolving the problem, as we try to avoid using this ticket tracker as a support channel.

comment:4 Changed 5 years ago by hernandocounty

Im not looking for support. I have the problem fixed by the method on the link I sent you by editing the urls.py instead of the settings.py and the TEMPLATE_DIRS method.

You guys are way ahead of guys like me. You guys understand this stuff in a different way . You wrote it Probably. But myself, I have a background in Physics and am about Jr Level Django guy.

I am honeslty trying to help the documentation, Not looking for Support.

Editing the urls.py solution is much faster and makes more sense to guys at my level IMHO.

the guy on the stack overflow even said in 1.7 things are different with TEMPLATES_DIRS and its only necessary to edit urls.py to achieve the result of changing the title of the admin site.

comment:5 Changed 5 years ago by hernandocounty

I followed the tutorial as best as a guy with a physics degree can. If it confuses me, It probably confuses a lot of other people too.

comment:6 Changed 5 years ago by hernandocounty

yes I am using the 1.7 tutorial.

I tried the other methods when the 1.7 version did not work.

There was no error message.. It was just that the Site Admin Text did not change unless I edited urls.py, which took all of 3 seconds as opposed to the 24 hours of trying the method on the tutorial.

Im not trying to be a dick man.. just trying to help and I know other people have had this problem.

comment:7 Changed 5 years ago by Tim Graham

Oh now I understand your suggestion. Well, we don't use that method for the reason described in the tutorial, "We use this approach to teach you how to override templates. In an actual project, you would probably use the django.contrib.admin.AdminSite.site_header attribute to more easily make this particular customization." So I am not sure what we should do. Suggestions?

comment:8 Changed 5 years ago by hernandocounty

Awesome. Wow man thanks for listening. Really Cool . Ok . Could we just make another section and just call it Alternative method to do this ? something simple. I really do feel like it fits the DRY principle . As for what is in the Tutorial. Is there something I missed that makes it difficult to execute ? I seriously spent quite a bit of time on it and would even be willing to start it over from scratch and screenshot it all . Maybe I would find a common mistake / pitfall that occurs for newbs like me ?

comment:9 Changed 5 years ago by Tim Graham

Component: Template systemDocumentation
Easy pickings: set
Summary: Templates override with Admin Site TEMPLATE_DIRS better method possiblyAdd a code example for custom AdminSite
Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization

I probably wouldn't include the alternative in the tutorial itself since site_header is already linked to the admin docs. The instructions are on that page:

"If you’d like to set up your own administrative site with custom behavior, however, you’re free to subclass AdminSite and override or add anything you like. Then, simply create an instance of your AdminSite subclass (the same way you’d instantiate any other Python class), and register your models and ModelAdmin subclasses with it instead of using the default."

but a code example would be helpful.

I'd guess maybe you didn't setup the directory structure quite right in order for template overriding to work. It should be mysite/templates/admin and not mysite/mysite/templates/admin.

comment:10 Changed 5 years ago by hernandocounty

Yes but even that method is too much. Like I said, The guy on stack overflow had the simplest solution of just editing urls.py

and yes I did have the templates directory in the right place.

I am seriously confused as to why it did not work. Everything you suggest I have tried.

I think the only solution is for me to start it over in a new VM and document my process. Until then we wont have the same data to work with .

comment:11 Changed 5 years ago by Berker Peksag

Has patch: set
Owner: changed from nobody to Berker Peksag
Status: newassigned

comment:12 Changed 5 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 4a9b4a23bdb51c9fce06facaf78c9ba0a54f1266:

Fixed #23575 -- Added a code example for custom AdminSite.

comment:13 Changed 5 years ago by Tim Graham <timograham@…>

In cb952099f4aeac263501c185441872af06927606:

[1.7.x] Fixed #23575 -- Added a code example for custom AdminSite.

Backport of 4a9b4a23bd from master

Note: See TracTickets for help on using tickets.
Back to Top