Sasa Blagojevic
Sasa Blagojevic

Reputation: 2200

Overriding Django admin vs creating new templates/views

I am a total noob with Django, I come from the PHP world and I am used to doing things differently.

I'm building an app and I want to change the way the backend looks, I want to use Bootstrap 4 and add a lot of custom stuff e.g. permission based admin views, and I was wondering what is the best practice, or how do more experienced django devs go about it?

Do they override all the django.contrib.admin templates, or do they build custom templates and login/register next to it, and use the django.contrib.admin only for the superuser?

What is the django way?

Upvotes: 1

Views: 630

Answers (2)

Mad Wombat
Mad Wombat

Reputation: 15125

Django admin is intended for administration purposes. For all intents and purposes it is a direct interface to your database. While I have seen some people building customer facing interfaces using admin, this is most definitely not the way to make a general Django web application.

You should define views for your models. You can use built-in APIs to login and authenticate users. You should most likely restrict access to admin to internal users only.

As for templates, the modern way of doing things is to dynamically fetch data using an API and do all the UI logic in Javascript. Django can be used very well to provide an API to a frontend. Look into Django REST Framework. The basic idea is to write serializers for your models and have view functions serve the serialized data to the front end.

You could go the old school way and render your pages using templates of course. In that case your views would render templates using data provided by your models.

Upvotes: 1

pissall
pissall

Reputation: 7409

Yes. The admin pages is actually for administering the webpage. For user login and registration you create the templates. However, if you want your backend to look different then you can tweak the template for the admin page, admin login page as well. And you can also have permission based admin views. It's okay to over ride the defaults as long as you know what you're doing. Hope that helped.

Upvotes: 0

Related Questions