django 配置xadmin

django xadmin本地安裝python

 

百度雲 下載,激活碼:bxhv,下載後不須要解壓,直接本地 pip install xxx.zipgit

django 版本須要 1.1.11,  github

1,添加app數據庫

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
'xadmin', 'crispy_forms', ]

2,配置urldjango

import xadmin

urlpatterns = [
    #xadmin後臺
    url(r'^xadmin/', xadmin.site.urls),
]

3,配置數據庫並進行同步七牛雲存儲

中間出現報錯信息,session

No module named 'django.core.urlresolvers

把原來的 django.core.urlresolvers 包 更改成了 django.urls包,便可app

4,在admin裏進行配置;測試

 

import xadmin

from carts.models import Cart

xadmin.site.register(Cart)

from xadmin import views
# 基本的修改
class BaseSetting(object):
    enable_themes = True   # 打開主題功能
    use_bootswatch = True  #

# 針對全局的
class GlobalSettings(object):
    site_title = "每天生鮮後臺管理系統"  # 系統名稱
    site_footer = "綠葉在線網"      # 底部版權欄
    # menu_style = "accordion"     # 將菜單欄收起來



# 註冊,注意一個是BaseAdminView,一個是CommAdminView
xadmin.site.register(views.BaseAdminView, BaseSetting)
xadmin.site.register(views.CommAdminView, GlobalSettings)

在配置的app 下:url

 

在應有的init文件中:

 

將咱們的靜態文件上傳至 七牛雲

pip install django-qiniu-storage    #安裝

setting.py  中配置:

STATIC_URL = '/static/'

#------------------------七牛雲存儲配置--------------------------------
QINIU_ACCESS_KEY = ''
QINIU_SECRET_KEY = ''
QINIU_BUCKET_NAME = 'fresh-every-day'
QINIU_BUCKET_DOMAIN = 'pk0opy1d6.bkt.clouddn.com/'                
DEFAULT_FILE_STORAGE = 'qiniustorage.backends.QiniuStorage'

 將上面配置完以後,咱們就用xadmin 測試下上傳圖片:

 


 

第二種方法:

本地安裝xadmin 方法:

1,先下載, 激活碼,wwmc,而後將這個包放在,如圖所示:

2,

分別把上面幾個包安裝下,

 

3,在setting裏配置:

STATIC_URL = '/static/'
MEDIA_URL = "/media/"

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

MEDIA_ROOT = os.path.join(BASE_DIR, "media")

而後將添加app:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'xadmin',  
    'crispy_forms',
]

4,添加上傳文件的url:

import xadmin
from django.views.static import serve
from muxue import settings

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^xadmin/', include(xadmin.site.urls)),
    url(r'^media/(?P<path>.*)$',serve,{"document_root":settings.MEDIA_ROOT})
]

 

目前xadmin基本配置完畢,咱們再來看xadmin中添加插件ueditor 下載,  激活碼:6dp6,放到上面圖示的位置

 

咱們看看怎麼用:

from DjangoUeditor.models import UEditorField

goods_desc = UEditorField(verbose_name=u"內容", imagePath="goods/images/", width=1000, height=300,
                              filePath="goods/files/", default='')

而後xadmin裏繼續看,(這裏注意,須要在你的應用裏新建 adminx.py 文件)

而後建立超級管理,便可登陸測試是否配置成功!

相關文章
相關標籤/搜索