Django,Django….不住不觉的就开始捣腾这个了…话说默认我安装的Django 1.6 跟Xadmin目前的版本是不够兼容的…故此我降到了1.5.x …xadmin的代码仍有一点小错误,毕竟开发者精力有限,可以体谅,修正后,目前未发现错误已经不兼容的问题..
安装pip
[root@i-it ~]# tar zxf pip-1.5.6.tar.gz [root@i-it ~]# cd pip-1.5.6 [root@i-it pip-1.5.6]# sh ../setuptools-0.6c11-py2.6.egg [root@i-it pip-1.5.6]# python setup.py install
安装django-crispy-forms(xadmin的依赖)
[root@i-it ~]# tar zxf django-crispy-forms-1.4.0.tar.gz [root@i-it ~]# cd django-crispy-forms-1.4.0 [root@i-it django-crispy-forms-1.4.0]# python setup.py install
安装django-reversion(xadmin的依赖(可选))
[root@i-it ~]# tar zxf django-reversion-1.5.5.tar.gz [root@i-it ~]# cd django-reversion-1.5.5 [root@i-it django-reversion-1.5.5]# python setup.py install
安装Django-Xadmin
[root@i-it ~]# unzip django-xadmin-master.zip [root@i-it ~]# cd django-xadmin-master [root@i-it django-xadmin-master]# python setup.py install
将xadmin 添加到INSTALL_APPS
INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'author', ############################ 'xadmin', 'crispy_forms', 'reversion', ############################ # Uncomment the next line to enable the admin: # 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', )
添加 URL-patterns 以及 autodiscover 操作
[root@i-it wdzj]# cat wdzj/urls.py | grep -v "#" from django.conf.urls import patterns, include, url import xadmin xadmin.autodiscover() from xadmin.plugins import xversion xversion.register_models() urlpatterns = patterns('', url(r'xadmin/', include(xadmin.site.urls)), )
收集media文件
[root@i-it wdzj]# python manage.py collectstatic
同步数据并runserver
[root@i-it wdzj]# python manage.py syncdb .... Creating tables ... Creating table reversion_revision Creating table reversion_version Creating table xadmin_bookmark Creating table xadmin_usersettings Creating table xadmin_userwidget .... [root@i-it wdzj]# python manage.py runserver 1.1.1.10:80
登录时错误
Request Method:GET Request URL:http://1.1.1.10/xadmin/ Django Version:1.5.8 Exception Type:KeyError Exception Value:'menu' [root@i-it wdzj]# vi /usr/lib/python2.6/site-packages/django_xadmin-0.5.0-py2.6.egg/xadmin/views/base.py 406 before_filter_length = len(item['menus'])
通过浏览器访问:
编辑urls注册之前写的author模块
from author.models import Profile xadmin.site.register(Profile)