环境:window7 x64、python3.4、django1.10
一、pip install xadmin安装报错
1、使用pip install xadmin命令安装可能报如下错误:
2、解决方案
亲测使用
pip install git+git://github.com/sshwsfc/xadmin.git
命令可以正常使用。
二、django项目中配置xadmin
- settings.py配置
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app.apps.AppConfig',
'xadmin',
'crispy_forms',
]
- urls.py配置
urlpatterns = [
# url(r'^admin/', admin.site.urls),
url(r'^xadmin/', xadmin.site.urls),
]
在blog/目录下创建adminx.py,增加如下内容:
from .models import Permission,Article,Category, ArticleComment, Type, Notice,EmailVerifyRecord
import xadmin
import xadmin.views as xviews class BaseSetting(object):
enable_themes = True
use_bootswatch = True
xadmin.site.register(xviews.BaseAdminView, BaseSetting) class AdminSettings(object):
# 设置base_site.html的Title
site_title = '管理后台'
# 设置base_site.html的Footer
site_footer = '2017 Admin'
menu_style = 'default' # 菜单设置
def get_site_menu(self):
return (
{'title': '文章管理', 'perm': self.get_model_perm(Article, 'change'), 'menus': (
{'title': '文章', 'icon': 'fa fa-vimeo-square'
, 'url': self.get_model_url(Article, 'changelist')},
{'title': '考试类别', 'icon': 'fa fa-vimeo-square'
, 'url': self.get_model_url(Category, 'changelist')},
{'title': '文章类别', 'icon': 'fa fa-vimeo-square'
, 'url': self.get_model_url(Type, 'changelist')},
{'title': '文章评论', 'icon': 'fa fa-vimeo-square'
, 'url': self.get_model_url(ArticleComment, 'changelist')},
)},
)
xadmin.site.register(xviews.CommAdminView, AdminSettings)
注意配置完了之后别忘了运行: python3 manage.py makemigrations、python3 manage.py migrate
至此,基本配置完成,可以访问http://localhost:8000/xadmin正常使用了。