django1.7+django_tinymce+flatpage配置

一、准备环境

  1、配置好python和django环境

  2、下载并且安装django_tinymce

    用pip进行安装(在安装python和django环境时自己手动安装,或者下载pip源码)

    pip install django_tinymce  (利用网络安装,稍等片刻即可安装完毕)

   3、装好后会在python库目录下发现tinymce目录(在我的linux下是这个样子的)  

tree  -L 1 /usr/local/python3.4/lib/python3.4/site-packages/tinymce/
/usr/local/python3.4/lib/python3.4/site-packages/tinymce/
├── compressor.py
├── __init__.py
├── media
├── models.py
├── __pycache__
├── settings.py
├── static
├── templates
├── templatetags
├── tests
├── urls.py
├── views.py
└── widgets.py

6 directories, 7 files

    4、然后在你的项目文件夹下面找到settings.py文件,打开进行配置

      (1)在INSTALLED_APPS里添加tinymce,如下所示      

 INSTALLED_APPS = (
      'django.contrib.admin',
      'django.contrib.auth',
      'django.contrib.contenttypes',
      'django.contrib.sessions',
      'django.contrib.messages',
      'django.contrib.staticfiles',
      'django.contrib.flatpages',
      'django.contrib.sites',
      'tinymce',
  )

    (2)接着在settings.py里添加如下内容

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')   #可以注释掉这句,然后向下面那样配置
MEDIA_URL = ''                                  #可以注释掉这句,然后向下面那样配置
TINYMCE_JS_URL = os.path.join(MEDIA_URL, "tiny_mce/tiny_mce.js") TINYMCE_JS_ROOT = os.path.join(MEDIA_ROOT, "tiny_mce")

或者这样配置也可以

TINYMCE_JS_ROOT = "tiny_mce"

TINYMCE_JS_URL = "tiny_mce/tiny_mce.js"

    (3)在你自己的项目目录里找到urls.py,打开添加如下内容

 urlpatterns += [
  
          url(r'^tinymce/', include('tinymce.urls')),
        ]

    (4)编辑vim  /usr/local/python3.4/lib/python3.4/site-packages/django/contrib/flatpages/forms.py 该文件

        添加以下内容

from django import forms
from django.contrib.flatpages.models import FlatPage
from tinymce.widgets import TinyMCE
class FlatPageForm(forms.ModelForm):
    ...代表原有内容
    content = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
    ...代表原有内容
    class Meta:
        model = FlatPage    

 

 

 

posted @ 2016-06-01 10:30  zw~菜园子  阅读(665)  评论(0编辑  收藏  举报