Xadmin is a Django management background implementation that uses a more flexible architecture design and bootstrap UI framework to replace the existing admin, Chinese development, with many new features:
- Compatible with Django Admin
- Using Bootstrap as the UI framework
- Edit Page Flexible layout
- Main Page dashboards and widgets
- Filter Hardening
- Data export
- Powerful plug-in mechanism
Integration with Django
This article takes the Simpleblog project as an example to explain how to integrate Xadmin in Django
python2.7 Environment Switch
Note that the previous tutorials are open in the python3.4 environment. So far xadmin can only support python2, so we're going to create a new branch py27 based on this project, and then we'll build a python2.7 virtual environment and switch to this environment.
Add dependency
In Requirements.txt, add the following dependencies, note: To use Xadmin's django1.9 branch
django-reversion==1.8.5 xlwt==0.7.5 Git+https://github.com/sshwsfc/[email protected]
|
Modify settings.py
The configuration for adding xadmin is as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 |
ADMINS = ( # (' Your Name ', ' [email protected] '), ) MANAGERS = ADMINS
# application Definition Installed_apps = ( # ... ' Xadmin ', ' Crispy_forms ', ' Reversion ', # ... )
|
Add a link to/xadmin
Modify the mysite/urls.py
following
1 2 3 4 5 6 7 8 9 10 11 12 |
#!/usr/bin/env python < span class= "comment" >#-*-encoding:utf-8-*- from django.conf.urls span class= "keyword" >import patterns, include, url # The version module automatically registers the Model from xadmin.plugins xversion.register_models () Urlpatterns = Patterns ( URL ( r ' xadmin/', include (Xadmin.site.urls), Name= ' Xadmin '), # ... /span> |
Create adminx.py
Create the adminx.py in the blog/directory, as follows
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
#!/usr/bin/env python #-*-Encoding:utf-8-*- """ Topic:adminx Custom Class Desc: """ Import Xadmin Import Xadmin.viewsAs Xviews From. ModelsImport Tag, Category, Post, Comment, Evaluate, Page From Xadmin.layoutImport Main, Tabholder, Tab, FieldSet, Row, Col, Appendedtext, Side
ClassBasesetting(object): Enable_themes =True Use_bootswatch =True Xadmin.site.register (xviews. Baseadminview, basesetting)
ClassAdminsettings(object): # set the title of base_site.html Site_title =' Blog Management Backstage ' # Set Base_site.html's footer Site_footer =' Winhong Inc ' Menu_style =' Default '
# Menu Settings DefGet_site_menu(self): Return ( {' Title ':' Blog Management ',' Perm ': self.get_model_perm (Page,' Change '),' Menus ': ( {' Title ':' All pages ',' Icon ':' FA Fa-vimeo-square ' ,' URL ': Self.get_model_url (Page,' Changelist ')}, { ' icon ': ' fa fa-vimeo-square ' ' URL ': Self.get_model_url ( Category, ' Changelist ')}, xadmin.site.register (xviews. Commadminview, adminsettings) xadmin.site.register (Page) xadmin.site.register (Category) # xadmin.site.register ( TAG) # xadmin.site.register (Post) # xadmin.site.register (comment) # xadmin.site.register ( Evaluate) |
Here, we register all the model in the xadmin so that the backend can manage them automatically. and customize some menus, headings, and so on in the background. Specific custom methods can refer to Xadmin's official documentation.
Add a management background link
To mysite/templates/mysite/base.html
add a/xamdin management background link to the template:
<div id= "meta-2" class= "widget Widget_meta" > <ul> {% if User.is_superuser%} <li><a href= "/xadmin" > Administration site </a></li> {% ENDIF%} {% if user.is_authenticated%} <li> <a href= "{% url ' django.contrib.auth.views.logout '%}" > Logout </a> </li> {% Else%} <li> <a href= "{% url ' django.contrib.auth.views.login '%}" > Login </a> </li> {% ENDIF%} <li><a href= "#" > Article <abbr title= "RSS" >RSS</abbr></a></li> </ul> </div>
|
Custom Background Landing Page
Create a new mysite/templates/registration/login.html
template, copy the login.html from the Xadmin module, modify its contents, and change it to the form you want.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
{% load staticfiles%} {% load i18n%} <Html> <Head> <MetaName="Viewport" Content="Width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" > <MetaName="description"Content="" > <MetaName="Author"Content="" > <MetaName="Robots"Content="None,noarchive" > <Title> User Login-Simpleblog</Title> <!--... Middle omitted ...--> <ScriptType="Text/javascript"Src="{% static ' xadmin/vendor/jquery/jquery.js '%}" ></Script> </Head> <Bodyclass="Login" > <Divclass="Container" > <FormMethod="POST"action="{% url ' django.contrib.auth.views.login '%}" > {% Csrf_token%} <Divclass="Panel Panel-default Panel-single"Id="Panel-login" > <Divclass="Panel-heading" > <H2class="Form-signin-heading" > Please Login</H2> </Div> <!--... Middle omitted ...--> </Div> </Form>
</Div> <!--... Middle omitted ...--> <ScriptType="Text/javascript"Src="{% static ' xadmin/js/xadmin.main.js '%}" ></Script> <ScriptType="Text/javascript"Src="{% static ' xadmin/js/xadmin.responsive.js '%}" ></Script> <script type= "Text/javascript" src= "{% static ' xadmin/vendor/jquery-ui/ Jquery.ui.effect.js '%} "></SCRIPT> Span class= "line" ><script type= " Text/javascript "src=</SCRIPT> Span class= "line" ></body>, </HTML> |
After these finishes, we open the app, access the 管理站点
link and should be able to see the login page as follows
Post-logon effects
Django1.9 Development Blog (14)-Integrated xadmin