django学习之xadmin后台管理部署

首先看下admin的后台管理界面(默认,未做任何设置)

都说xadmin很吊,吊炸天,我就拿过来撸了一把,发现事实并不是这样的,我只能说一句,最合适自己的才是最好的,还是自己撸吧,偶尔借鉴下还是可以的~ 不要太沉迷于这些框架~

开工~

安装须知:

  • django >=1.4
  • django-crispy-forms >=1.2.3 (For xadmin crispy forms)
  • django-reversion ([OPTION] For object history and reversion feature, please select right version by your django, see changelog )
  • xlwt ([OPTION] For export xls files)
  • xlsxwriter ([OPTION] For export xlsx files)

个人建议:

  • 建议使用django==1.5的版本,高或者低都有bug,亲测
  • 有bug,请提交,为xadmin贡献一下,当然能自我修复bug并提交,最好不过了
  • 感谢作者~
  • 本篇文章只是简单的安装,没有涉及到真正的应用,so~

步骤:

  1. 创建虚拟环境
[[email protected] ~]# pythonbrew venv create dj
Creating `dj` environment into /root/.pythonbrew/venvs/Python-2.7.6
Already using interpreter /root/.pythonbrew/pythons/Python-2.7.6/bin/python
New python executable in /root/.pythonbrew/venvs/Python-2.7.6/dj/bin/python
Installing setuptools............done.
Installing pip...............done.
[[email protected] ~]# pythonbrew venv use dj
# Using `dj` environment (found in /root/.pythonbrew/venvs/Python-2.7.6)
# To leave an environment, simply run `deactivate`
(dj)[[email protected] ~]# ls

2、安装django==1.5

(dj)[[email protected] ~]# pip install ‘django==1.5‘
Downloading/unpacking django==1.5
  Downloading Django-1.5.tar.gz (8.0MB): 8.0MB downloaded
  Running setup.py egg_info for package django
    
    warning: no previously-included files matching ‘__pycache__‘ found under directory ‘*‘
    warning: no previously-included files matching ‘*.py[co]‘ found under directory ‘*‘
Installing collected packages: django
  Running setup.py install for django
    changing mode of build/scripts-2.7/django-admin.py from 644 to 755
    
    warning: no previously-included files matching ‘__pycache__‘ found under directory ‘*‘
    warning: no previously-included files matching ‘*.py[co]‘ found under directory ‘*‘
    changing mode of /root/.pythonbrew/venvs/Python-2.7.6/dj/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
(dj)[[email protected] ~]#

3、创建一个名为blog的项目

(dj)[[email protected] ~]# django-admin.py startproject blog
(dj)[[email protected] ~]# cd blog/
(dj)[[email protected] blog]# ls
blog  manage.py
(dj)[[email protected] blog]# tree .
.
├── blog
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py
1 directory, 5 files

4、创建一个名为polls的app

(dj)[[email protected] blog]# python manage.py startapp polls
(dj)[[email protected] blog]# ls
blog  manage.py  polls
(dj)[[email protected] blog]# ll
total 12
drwxr-xr-x 2 root root 4096 Dec  2 03:29 blog
-rw-r--r-- 1 root root  247 Dec  2 03:28 manage.py
drwxr-xr-x 2 root root 4096 Dec  2 03:29 polls

安装xadmin

(dj)[[email protected] blog]# pip install django-xadmin
Downloading/unpacking django-xadmin
  Downloading django-xadmin-0.5.0.tar.gz (1.0MB): 1.0MB downloaded
  Running setup.py egg_info for package django-xadmin
    
Requirement already satisfied (use --upgrade to upgrade): setuptools in /root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg (from django-xadmin)
Requirement already satisfied (use --upgrade to upgrade): django>=1.5 in /root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/site-packages (from django-xadmin)
Downloading/unpacking django-crispy-forms>=1.4.0 (from django-xadmin)
  Downloading django-crispy-forms-1.4.0.tar.gz (47kB): 47kB downloaded
  Running setup.py egg_info for package django-crispy-forms
    
    warning: no files found matching ‘*‘ under directory ‘crispy_forms/static‘
Installing collected packages: django-xadmin, django-crispy-forms
  Running setup.py install for django-xadmin
    
  Running setup.py install for django-crispy-forms
    
    warning: no files found matching ‘*‘ under directory ‘crispy_forms/static‘
Successfully installed django-xadmin django-crispy-forms
Cleaning up...
(dj)[[email protected] blog]#

调整相关参数让xadmin可以正常访问

  1. 在settings文件中添加刚才我们创建的polls这个app
DATABASES = {
    ‘default‘: {
        ‘ENGINE‘: ‘django.db.backends.sqlite3‘, # Add ‘postgresql_psycopg2‘, ‘mysql‘, ‘sqlite3‘ or ‘oracle‘.           # 设置数据库使用sqlite3
        ‘NAME‘: ‘db.sqlite3‘,                      # Or path to database file if using sqlite3.                                         # 数据库名称为db.sqlite3
        # The following settings are not used with sqlite3:
        ‘USER‘: ‘‘,
        ‘PASSWORD‘: ‘‘,
        ‘HOST‘: ‘‘,                      # Empty for localhost through domain sockets or ‘127.0.0.1‘ for localhost through TCP.
        ‘PORT‘: ‘‘,                      # Set to empty string for default.
    }
}
INSTALLED_APPS = (
    ‘django.contrib.auth‘,
    ‘django.contrib.contenttypes‘,
    ‘django.contrib.sessions‘,
    ‘django.contrib.sites‘,
    ‘django.contrib.messages‘,
    ‘django.contrib.staticfiles‘,
    # Uncomment the next line to enable the admin:
    # ‘django.contrib.admin‘,
    # Uncomment the next line to enable admin documentation:
    # ‘django.contrib.admindocs‘,
    ‘polls‘,  # 添加该行
    ‘xadmin‘, # 添加该行
)

2、设置urls文件

from django.conf.urls import patterns, include, url
import xadmin                 # 添加该行
xadmin.autodiscover()     # 添加该行
# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
# admin.autodiscover()
from xadmin.plugins import xversion    # 添加该行
xversion.registe_models()                    # 添加该行
urlpatterns = patterns(‘‘,
    # Examples:
    # url(r‘^$‘, ‘blog.views.home‘, name=‘home‘),
    # url(r‘^blog/‘, include(‘blog.foo.urls‘)),
    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r‘^admin/doc/‘, include(‘django.contrib.admindocs.urls‘)),
    # Uncomment the next line to enable the admin:
    # url(r‘^admin/‘, include(admin.site.urls)),
    url(r‘^xadmin/‘, include(xadmin.site.urls)),            # 添加该行
)

3、收集media信息

(dj)[[email protected] blog]# python manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings.
This will overwrite existing files!
Are you sure you want to do this?
Type ‘yes‘ to continue, or ‘no‘ to cancel: yes
0 static files copied.
(dj)[[email protected] blog]#

4、同步数据库

(dj)[[email protected] blog]# python manage.py syncdb
Creating tables ...
Creating table auth_permission
Creating table auth_group_permissions
Creating table auth_group
Creating table auth_user_groups
Creating table auth_user_user_permissions
Creating table auth_user
Creating table django_content_type
Creating table django_session
Creating table django_site
You just installed Django‘s auth system, which means you don‘t have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (leave blank to use ‘root‘): zhuima
Email address: 
Password: 
Password (again): 
Superuser created successfully.
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
(dj)[[email protected] blog]#

5、开启服务,前台登陆测试

(dj)[[email protected] blog]# python manage.py runserver 0.0.0.0:80
Validating models...
0 errors found
December 01, 2014 - 20:59:40
Django version 1.5, using settings ‘blog.settings‘
Development server is running at http://0.0.0.0:80/
Quit the server with CONTROL-C.

6、出现报错

AttributeError at /xadmin/
‘module‘ object has no attribute ‘atomic‘
Request Method:GET
Request URL:http://192.168.58.21/xadmin/
Django Version:1.5
Exception Type:AttributeError
Exception Value:
‘module‘ object has no attribute ‘atomic‘
Exception Location:/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/site-packages/reversion/admin.py in VersionAdmin, line 384
Python Executable:/root/.pythonbrew/venvs/Python-2.7.6/dj/bin/python
Python Version:2.7.6
Python Path:
[‘/root/blog‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg‘,
 ‘/root/.pythonbrew/pythons/Python-2.7.6/lib‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python27.zip‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/plat-linux2‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/lib-tk‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/lib-old‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/lib-dynload‘,
 ‘/root/.pythonbrew/pythons/Python-2.7.6/lib/python2.7‘,
 ‘/root/.pythonbrew/pythons/Python-2.7.6/lib/python2.7/plat-linux2‘,
 ‘/root/.pythonbrew/pythons/Python-2.7.6/lib/python2.7/lib-tk‘,
 ‘/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/site-packages‘]
Server time:Mon, 1 Dec 2014 21:29:24 -0600

6、解决办法(个人解决方法,不建议采用)

注释掉`/root/.pythonbrew/venvs/Python-2.7.6/dj/lib/python2.7/site-packages/reversion/admin.py in VersionAdmin, line 384` 文件中包含`atomic`字样的信息,然后重启服务即可

7、前端显示

再次感谢xadmin的作者~

时间: 2024-07-30 08:19:03

django学习之xadmin后台管理部署的相关文章

第三百八十节,Django+Xadmin打造上线标准的在线教育平台—将所有app下的models数据库表注册到xadmin后台管理

第三百八十节,Django+Xadmin打造上线标准的在线教育平台-将所有app下的models数据库表注册到xadmin后台管理 将一个app下的models数据库表注册到xadmin后台管理 重点:xadmin的数据表注册,是到app下查找的adminx文件,所以我们必须在app下创建一个adminx.py文件,所有关于数据表注册到xadmin后台的代码都是写在adminx.py文件里 adminx.py文件编写 1.自定义一个类来继承object对象,这个类叫做数据表管理器 数据表管理器里

安装xadmin后台管理

安装xadmin后台管理 下载xadmin源码包 https://github.com/sshwsfc/xadmin 得到 xadmin-master.zip 安装xadmin-master.zip 注意:需要先加入压缩包,把README.rst用一个同名的空文件替换 (Django_login) D:\>pip install xadmin-master.zip Processing d:\xadmin-master.zip Requirement already satisfied: set

django,访问xadmin后台报错Exception Value: (1146, "Table 'django.xadmin_usersettings' doesn't exist")

报错如图: 解决,执行迁移表命令: python manage.py makemigrations python manage.py migrate 生成xadmin数据库表之后再去访问: 如图: 访问成功: django,访问xadmin后台报错Exception Value: (1146, "Table 'django.xadmin_usersettings' doesn't exist") 原文地址:https://www.cnblogs.com/xiamaojjie/p/125

Django扩展xadmin后台管理

python:3.7.2django:2.1.2 githup:https://github.com/sshwsfc/xadmin 安装xadmin django版本2.0及以上一不能使用pip install xadmin进行安装,根据作者的安装说明使用一下命令直接从githup安装 pip install git+git://github.com/sshwsfc/xadmin.git@django2 现有项目引入xadmin settings.py设置引入xadmin应用 INSTALLED

django基础知识之后台管理Admin站点:

Admin站点 通过使用startproject创建的项目模版中,默认Admin被启用 1.创建管理员的用户名和密码 python manage.py createsuperuser 然后按提示填写用户名.邮箱.密码 2.在应用内admin.py文件完成注册,就可以在后台管理中维护模型的数据 from django.contrib import admin from models import * admin.site.register(HeroInfo) 查找admin文件:在INSTALLE

Pycharm+Django+Python+MySQL开发 后台管理数据库

Django框架十分简单易用,适合搭建个人博客网站.网上有很多教程,大多是关于命令行操作Django,这里分享一些用最新工具进行Django开发过程,主要是PyCharm太强大,不用有点可惜. 第一次写技术开发类的博文,可能抓不到重点,详略也可能失衡,感谢支持. 环境&工具:Windows server 2012  , PyCharm 2016.2.1 , Django 1.10 , Python 2.7 , MySQL Community 5.7.14 0.创建前的配置 安装MySQL,并已设

Linux下开发python django程序(设置admin后台管理上传文件)

1.项目创建相关工作参考前面 2.在models.py文件中定义数据库结构 import django.db import modelsclass RegisterUser(models.Model): username=models.CharField(max_length=30) headImg = models.FileField(upload_to='./upload/') def __unicode__(self): return self.username 3.生成数据库 pytho

Linux下开发python django程序(设置admin后台管理模块)

1.新建项目和项目下APP django-admin startproject csvt03 django-admin startapp app1 2.修改settings.py文件 设置默认安装APP INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages

xadmin后台管理

安装 # >: pip install https://codeload.github.com/sshwsfc/xadmin/zip/django2 配置文件注册app: INSTALLED_APPS = [ # ... # xamin主体模块 'xadmin', # 渲染表格模块 'crispy_forms', # 为模型通过版本控制,可以回滚数据 'reversion', ] 完成自己数据库模型类数据库迁移 python manage.py makemigrations python man