开放源码的内容管理系统,基于Web框架Django的。
优势如下
pip 安装,cmd命令行工具
easy_install pip
pip install Django==1.5 django-cms south
直接用easy_install 安装,cmd命令行工具
easy_install django-cms
应用,
1.新建django项目,cmd进入到工作目录
django-admin.py startproject myproject
2.修改配置文件 myproject/myproject/settings.py
顶部加上
设置语言# -*- 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. } }
middleware_class配置# 上传文件保存目录,绝对路径 STATIC_ROOT = os.path.join(PROJECT_PATH, "static") STATIC_URL = "/static/" #静态文件目录,绝对地址,例如 js css文件 MEDIA_ROOT = os.path.join(PROJECT_PATH, "media") MEDIA_URL = "/media/"
新加配置TEMPLATE_CONTEXT_PROCESSORSMIDDLEWARE_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 = ( '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', )
cms-模板#模板目录 TEMPLATE_DIRS = (. os.path.join(PROJECT_PATH, "templates"), )
install_app配置CMS_TEMPLATES = ( ('template_1.html', 'Template One'), ('template_2.html', 'Template Two'), )
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切换到项目根目录,创建完数据表根据提示创建后台登录用户
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