设为首页 收藏本站
查看: 1680|回复: 0

[经验分享] django学习之xadmin后台管理部署

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-4 09:24:30 | 显示全部楼层 |阅读模式
首先看下admin的后台管理界面(默认,未做任何设置)
wKioL1R-hzfBRFW_AAFeC6-wTqs701.jpg
wKiom1R-hsyxJ8p-AAIlDobRqDc811.jpg

都说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
2
3
4
5
6
7
8
9
10
[iyunv@php ~]# 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.
[iyunv@php ~]# pythonbrew venv use dj
# Using `dj` environment (found in /root/.pythonbrew/venvs/Python-2.7.6)
# To leave an environment, simply run `deactivate`
(dj)[iyunv@php ~]# ls




2、安装django==1.5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
(dj)[iyunv@php ~]# 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)[iyunv@php ~]#




3、创建一个名为blog的项目
1
2
3
4
5
6
7
8
9
10
11
12
13
(dj)[iyunv@php ~]# django-admin.py startproject blog
(dj)[iyunv@php ~]# cd blog/
(dj)[iyunv@php blog]# ls
blog  manage.py
(dj)[iyunv@php blog]# tree .
.
├── blog
│   ├── __init__.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py
1 directory, 5 files




4、创建一个名为polls的app
1
2
3
4
5
6
7
8
(dj)[iyunv@php blog]# python manage.py startapp polls
(dj)[iyunv@php blog]# ls
blog  manage.py  polls
(dj)[iyunv@php 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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(dj)[iyunv@php 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)[iyunv@php blog]#




调整相关参数让xadmin可以正常访问
  • 在settings文件中添加刚才我们创建的polls这个app
1
2
3
4
5
6
7
8
9
10
11
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.
    }
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
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文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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信息
1
2
3
4
5
6
7
8
(dj)[iyunv@php 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)[iyunv@php blog]#




4、同步数据库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(dj)[iyunv@php 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)[iyunv@php blog]#




5、开启服务,前台登陆测试
1
2
3
4
5
6
7
(dj)[iyunv@php 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、出现报错
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
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、前端显示
wKioL1R-ikjBUQAoAAGHqUNQBq0740.jpg wKiom1R-ibzyfebgAAFmclWG8-I589.jpg


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-35492-1-1.html 上篇帖子: redhat双网卡绑定配置 下篇帖子: Centos 5.3环境安装Coreseek 后台管理
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表