Environment: python2.7+django1.9
1, first download django-suti
pip install django-suit
2. Configuration project
Open, then find ------------------------INSTALLED_APPS
Write 'suit', before ''.
INSTALLED_APPS = [ 'suit', '', '', '', '', '', '', ]
Modify the language, region, and time format:
LANGUAGE_CODE = 'zh-Hans' TIME_ZONE = 'Asia/Shanghai' DATETIME_FORMAT = 'Y-m-d H:i:s' DATE_FORMAT = 'Y-m-d'
Additional knowledge:Use django-suit template to add customized menus and customized pages in the admin backend, set access rights
1, first inside the SUIT_CONFIG add configuration, we usually add the configuration are app type, we need to customize the page, it can not be used app, you need to use the url, which we use the following:
# django-suit config SUIT_CONFIG = { 'ADMIN_NAME': 'X·X', 'HEADER_DATE_FORMAT': '', 'HEADER_TIME_FORMAT': 'H:i', 'SHOW_REQUIRED_ASTERISK': True, 'CONFIRM_UNSAVED_CHANGES': True, 'LIST_PER_PAGE': 20, 'MENU_OPEN_FIRST_CHILD': True, 'MENU': ( # sites is the default original apps and models # 'sites', '-', {'app': 'auth', 'label': u'Permission Management', 'icon': 'icon-lock'}, '-', {'app': 'duser', 'label': u'Platform users', 'icon': 'icon-user'}, '-', {'app': 'dtheme', 'label': u'Theme Management', 'icon': 'icon-tags'}, '-', {'app': 'dpost', 'label': u'Article Management', 'icon': 'icon-edit'}, '-', # If you use an absolute path like http, the menu will not expand and will not be marked as active. {'url': '/admin/theme/mysql', 'label': u'Third Data', 'icon': 'icon-lock'}, '-', {'label': u'Statistical data', 'icon': 'icon-tags', 'models': ( {'url': '/admin/theme/data', 'label': u'First Data'}, {'url': '/admin/theme/show', 'label': u'Second data'} )} ) }
2, and then is to add the route inside, the route must be added in front of, because otherwise, it will first go inside to match, resulting in confusion or error.
from dtheme import views urlpatterns = [ # The first one is the path to the url we added ourselves # url(r'^admin/theme/data', ), url(r'^admin/', ), url(r'^api/user/', include('')), url(r'^api/post/', include('')), url(r'^api/theme/', include('')), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
3, then, is to write views, we if dtheme module views to write:
def data(request):
return render(request, "")
4, please note that the reason why we can use directly above, because we created a templates folder under the dtheme module, and then put in it, it will scan this folder to find the template. So what is this template written as? We just wrote something random. It should be noted that we need to inherit base_site.html, otherwise the header and footer, and the left menu and so on are gone, equivalent to who does not inherit. The content will be written inside the content.
{% extends "admin/base_site.html" %} {% block content %} hello, new page. {% endblock %}
5、OVER。
6, back, it's not over. This time if we log out from the background, and then directly in the browser enter http://127.0.0.1:8000/admin/theme/dataif (coming after a conditional clause), found that you can still directly access this page, enter the management of the background of the other pages it will ask you to verify. So we customize this page is still very dangerous, other people know the URL can directly access it, our idea is actually very simple ah, we do not want to engage in special, in this regard, the security, only requirements and other background pages on the line: that is, the user in the access to these background pages when you want to do a user authentication, if the user is logged in, you can access, not logged in did not pass the authentication, you can not access. If the user is not logged in and has not passed the verification, the user will not be able to access the page and will be redirected directly to the login page. This needs to be set up in the view.
from import staff_member_required def data(request): return render(request, "") data = staff_member_required(data)
See the change above? It's that we've introduced a staff_member_required module, which is used to validate whether or not you're an insider (i.e. whether or not you're logged in). Of course, we're going to put our view function in it. That's all we need to do.
7, there is a how to add a custom page to auth inside the pit, to be studied and then come back to add.
Above this django beautification backend django-suit installation and configuration operation is all that I have shared with you, I hope to be able to give you a reference, and I hope you will support me more.