====== Django-cms project ====== ===== Installing django-cms ===== reference: http://docs.django-cms.org/en/2.2/getting_started/tutorial.html User virtualenv and pip to avoid dependency problems. $ yum install python2.6 python-setuptools python-imaging $ virtualenv mysite-env $ source mysite-env/bin/activate (env)$ pip install django==1.3.1 django-cms south (env)$ django-admin.py startproject mycmsproject Starting project may issue error PIL (python image lib) not installed. Installing PIL requires python-devel to compile PIL: $ sudo yum install python-devel (env)$ pip search PIL (env)$ pip install PIL (env)$ pip install django-filer cmsplugin-filer (env)$ pip install django-reversion ==== settings.py ==== Installed apps INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', 'django.contrib.staticfiles', 'cms', 'menus', 'mptt', 'south', 'filer', 'cmsplugin_filer_file', 'cmsplugin_filer_folder', 'cmsplugin_filer_image', 'cmsplugin_filer_teaser', 'cmsplugin_filer_video', 'cms.plugins.text', ## disabled due to filer #'cms.plugins.picture', #'cms.plugins.file', ## 'cms.plugins.link', 'cms.plugins.snippet', 'cms.plugins.googlemap', 'sekizai', # cmsplugin-blog 'cmsplugin_blog', 'simple_translation', #'staticfiles', 'tagging', 'missing', 'guardian', # optional ) Middleware classes MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'cms.middleware.multilingual.MultilingualURLMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.toolbar.ToolbarMiddleware', 'cmsplugin_blog.middleware.MultilingualBlogEntriesMiddleware', ) 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', ) ==== urls.py ==== 1 from django.conf.urls.defaults import * 2 from django.contrib import admin 3 from django.conf import settings 4 5 admin.autodiscover() 6 7 urlpatterns = patterns('', 8 url(r'^admin/', include(admin.site.urls)), 9 url(r'^', include('cms.urls')), 10 ) 11 12 if settings.DEBUG: 13 urlpatterns = patterns('', 14 url(r'^media/(?P.*)$', 'django.views.static.serve', 15 {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), 16 url(r'', include('django.contrib.staticfiles.urls')), 17 ) + urlpatterns 18 ==== templates ==== ===CMS_TEMPLATES setting:=== CMS_TEMPLATES = ( ('template_1.html', 'Template One'), ('template_2.html', 'Template Two'), ) === templates files === Inside folder pjs_root/templates base.html {% load cms_tags sekizai_tags %} {% render_block "css" %} {% placeholder base_content %} {% block base_content%}{% endblock %} {% render_block "js" %} template_1.html {% extends "base.html" %} {% load cms_tags %} {% block base_content %} {% placeholder template_1_content %} {% endblock %} **Template for cmsplugin-blog must contain a 'content' block** {% placeholder content %} as seen in cmsplugin_blog/templates/cmsplugin_blog/entry_detail.html 13 {% with object.placeholders|choose_placeholder:"content" as content %} 14 {% render_placeholder content %} 15 {% endwith %} ==== static files ==== At the moment static files in dev mode do not work quite 'out of the box'. Sometime when a site is openned, the runserver console says it can not find a certain js or css files. The best way for now is to collect all static files and add their folder to static file settings. === collect all static files === Use staticfiles modul to copy all static files in STATIC_ROOT dir, in this case the 'static' folder. This is normally done when the site is deployed. ./manage.py collectstatic then mv static static_dev Now add the static_dev to settings 76 77 STATICFILES_DIRS = ( 78 os.path.join(PROJECT_DIR, 'static_dev'), 79 ) 80 ===== Installing cmsplugin-blog ===== http://readthedocs.org/docs/django-cms/en/latest/ ===== Customizing template ===== ==== some free template ==== * http://all-free-download.com/free-website-templates/magazine-templates.html ==== customizing a template ==== ===== Django-cms-themes ===== ==== Using themes form www.djangocmsthemes.com ==== User can use an app to download themes from the website and upload/apply them using 'admin' interface. **It does not work properly at the moment** http://www.djangocmsthemes.com/getting-started install the django-cms-themes pluggable django app. The best way to do this is to use the command "pip install django-cms-themes" (if you are using pip). Add 'cms_themes' to INSTALLED_APPS in your settings file. Make sure you have a setting in your settings.py file called PROJECT_DIR, which should point to the root of your project in the filesystem, i.e. PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) Run "python manage.py syncdb" (or "python manage.py migrate" if you have south installed). ==== Making your own themes based on www.djangocmsthemes.com ==== === download and extract themes === Themes for the website are installed to 'themes' folder inside your webroot. CSS links and images are configured with this default path. [td@localhost vfoss_cms]$ tree themes themes ├── simple │   ├── static │   │   ├── css │   │   │   └── style.css │   │   └── images │   │   ├── bullet.png │   │   ├── graphic.png │   │   ├── paperclip.png │   │   └── pattern.png │   └── templates │   └── index.html └── summer ├── static │   ├── css │   │   └── styles.css │   ├── images │   │   ├── 1.jpg │   │   ├── 2.jpg │   │   ├── 3.jpg │   │   ├── 4.jpg │   │   ├── body-bg.jpg │   │   ├── tabs_1.gif │   │   └── tabs_2.gif │   └── js │   ├── jquery-1.3.2.min.js │   ├── jquery.cycle.all.min.js │   ├── script.js │   └── superfish.js └── templates ├── content.html └── index.html === Edit settings.py to make these themes available as templates === -------- settings.py ------------ ... 100 CMS_TEMPLATES = ( 101 ('example.html', 'Example Template'), 102 ('template_1.html', 'Template 1'), 103 ('template_2.html', 'Template 2'), 104 ('summer/templates/index.html', 'summer'), <===== make index.html a template. 105 ) 106 107 ROOT_URLCONF = 'urls' 108 109 TEMPLATE_DIRS = ( 110 os.path.join(PROJECT_DIR, 'templates'), 111 os.path.join(PROJECT_DIR, 'themes'), <==== add template dir. 112 ) 113 ... ===== Error & solution ===== ==== js & css files under /static/ can't be found ==== Problem: Cause: django dev-enviroment doesn't serve static file. Before deployment `python manage.py collectstatic` must be run so that all static files are copied to "settings.STATIC_ROOT" by python-staticfiles. See python-staticfiles documentation. Solution: move all static files to 'static-dev' and add 'os.path.join(PROJECT_PATH, "static-dev/jquery/"),' to 'settings.STATICFILES_DIRS'.