開放源碼的內容管理系統,基於Web框架Django的。css
優點以下html
安裝方法前端
pip 安裝,cmd命令行工具python
easy_install pip pip install Django==1.5 django-cms south
直接用easy_install 安裝,cmd命令行工具mysql
easy_install django-cms
應用,sql
1.新建django項目,cmd進入到工做目錄數據庫
django-admin.py startproject myproject
2.修改配置文件 myproject/myproject/settings.pydjango
頂部加上瀏覽器
# -*- coding: utf-8 -*- import os gettext = lambda s: s PROJECT_PATH = os.path.split(os.path.abspath(os.path.dirname(__file__)))[0]設置語言LANGUAGES = [ ('en', 'English'), ] LANGUAGE_CODE = 'en-us'
數據庫配置DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 'NAME': 'django_cms', # Or path to database file if using sqlite3. # The following settings are not used with sqlite3: 'USER': 'root', 'PASSWORD': '123456', 'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP. 'PORT': '3306', # Set to empty string for default. } }文件路徑配置# 上傳文件保存目錄,絕對路徑 STATIC_ROOT = os.path.join(PROJECT_PATH, "static") STATIC_URL = "/static/" #靜態文件目錄,絕對地址,例如 js css文件 MEDIA_ROOT = os.path.join(PROJECT_PATH, "media") MEDIA_URL = "/media/"middleware_class配置
MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.middleware.doc.XViewMiddleware', 'django.middleware.common.CommonMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cms.middleware.language.LanguageCookieMiddleware', )新加配置TEMPLATE_CONTEXT_PROCESSORS
TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', 'django.core.context_processors.i18n', 'django.core.context_processors.request', 'django.core.context_processors.media', 'django.core.context_processors.static', 'cms.context_processors.media', 'sekizai.context_processors.sekizai', )模板目錄配置#模板目錄 TEMPLATE_DIRS = (. os.path.join(PROJECT_PATH, "templates"), )cms-模板CMS_TEMPLATES = ( ('template_1.html', 'Template One'), ('template_2.html', 'Template Two'), )install_app配置INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'cms', 'mptt', 'menus', 'south', 'sekizai', 'cms.plugins.file', 'cms.plugins.flash', 'cms.plugins.googlemap', 'cms.plugins.link', 'cms.plugins.picture', 'cms.plugins.snippet', 'cms.plugins.teaser', 'cms.plugins.text', 'cms.plugins.video', 'cms.plugins.twitter', # Uncomment the next line to enable the admin: 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs', )
建立數據,cmd切換到項目根目錄,建立完數據表根據提示建立後臺登陸用戶session
python manage.py syncdb --all
修改url路由文件 myproject/myproject/urls.py 爲如下內容
from django.conf.urls.defaults import * from django.conf.urls.i18n import i18n_patterns from django.contrib import admin from django.conf import settings admin.autodiscover() urlpatterns = i18n_patterns('', url(r'^admin/', include(admin.site.urls)), url(r'^', include('cms.urls')), ) if settings.DEBUG: urlpatterns = patterns('', url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), url(r'', include('django.contrib.staticfiles.urls')), ) + urlpatterns
項目根目錄下( myproject/ )下增長文件夾 及文件
media static templates/base.html templates/template_1.html templates/template_2.html
base.html
{% load cms_tags sekizai_tags %} <html> <head> {% render_block "css" %} </head> <body> {% cms_toolbar %} {% placeholder base_content %} {% block base_content %}{% endblock %} {% render_block "js" %} </body> </html>
template_1.html
{% extends "base.html" %} {% load cms_tags %} {% block base_content %} {% placeholder template_1_content %} {% endblock %}
template_2.html
{% extends "base.html" %} {% load cms_tags %} {% block base_content %} {% placeholder template_2_content %} {% endblock %}
運行項目 cmd 項目根目錄
python manage.py runserver
瀏覽器打開 http://192.168.137.100:8000
後臺地址爲 http://192.168.137.100:8000/admin