2014-01-08 32 views
1

我想在django中使用TinyMCE编辑器或任何其他文本编辑器来获取textarea。我很难找到一个很好的例子或教程。在YouTube上发现了一个视频,但速度太快让我无法理解。任何指导都会有帮助。谢谢。

django的TinyMCE

settings.py

""" 
Django settings for ali project. 

For more information on this file, see 
https://docs.djangoproject.com/en/1.6/topics/settings/ 

For the full list of settings and their values, see 
https://docs.djangoproject.com/en/1.6/ref/settings/ 
""" 

# Build paths inside the project like this: os.path.join(BASE_DIR, ...) 
import os 
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) 

# Django settings for corating project. 

PROJECT_DIR = os.path.dirname(__file__) 

print 'BASE_DIR ',BASE_DIR 
print 'PROJECT_DIR ',PROJECT_DIR 
# Quick-start development settings - unsuitable for production 
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ 

# SECURITY WARNING: keep the secret key used in production secret! 
SECRET_KEY = '-=153zwy^8$sz%gsw#[email protected](4tc$j-h4(^3s+zw+' 

# SECURITY WARNING: don't run with debug turned on in production! 
DEBUG = True 

TEMPLATE_DEBUG = True 

ALLOWED_HOSTS = [] 




# Application definition 

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

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
) 

ROOT_URLCONF = 'ali.urls' 

WSGI_APPLICATION = 'ali.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.6/ref/settings/#databases 

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.sqlite3', 
     'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    } 
} 

# Internationalization 
# https://docs.djangoproject.com/en/1.6/topics/i18n/ 

LANGUAGE_CODE = 'en-us' 

TIME_ZONE = 'UTC' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.6/howto/static-files/ 


STATIC_ROOT = os.path.join(PROJECT_DIR, 'static_root') 
# URL prefix for static files. 
# Example: "http://example.com/static/", "http://static.example.com/" 
STATIC_URL = '/static/' 

# Additional locations of static files 
STATICFILES_DIRS = (
    os.path.join(PROJECT_DIR, 'static'), 
    # Put strings here, like "/home/html/static" or "C:/www/django/static". 
    # Always use forward slashes, even on Windows. 
    # Don't forget to use absolute paths, not relative paths. 
) 

TINYMCE_JS_URL = os.path.join(STATIC_URL, "js/tiny_mce/tiny_mce.js") 
TINYMCE_JS_ROOT = os.path.join(STATIC_URL, "js/tiny_mce") 

print "TINYMCE_JS_ROOT ",TINYMCE_JS_ROOT 
print "TINYMCE_JS_URL ",TINYMCE_JS_URL 


TEMPLATE_DIRS = (
    '/home/hussain/django/ali/ali/templates/', 
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". 
    # Always use forward slashes, even on Windows. 
    # Don't forget to use absolute paths, not relative paths. 
) 

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 

views.py

from django.shortcuts import render_to_response 
from page.forms import FlatPageForm 

def HomePage(request): 
    form = FlatPageForm() 
    print " form :: ",form 
    return render_to_response('HomePage.html',{'form':form}) 

urls.py

from django.conf.urls import patterns, include, url 
from ali.views import HomePage 
from django.contrib import admin 
admin.autodiscover() 

urlpatterns = patterns('', 
    # Examples: 
    # url(r'^$', 'ali.views.home', name='home'), 
    # url(r'^blog/', include('blog.urls')), 

    #url(r'^admin/', include(admin.site.urls)), 
    url(r'^home/', 'ali.views.HomePage'), 
    url(r'^tinymce/', include('tinymce.urls')), 

) 

错误:

Environment: 


Request Method: GET 
Request URL: http://localhost:8000/home/ 

Django Version: 1.6.1 
Python Version: 2.7.3 
Installed Applications: 
('django.contrib.admin', 
'django.contrib.auth', 
'django.contrib.contenttypes', 
'django.contrib.sessions', 
'django.contrib.messages', 
'django.contrib.staticfiles', 
'tinymce') 
Installed Middleware: 
('django.contrib.sessions.middleware.SessionMiddleware', 
'django.middleware.common.CommonMiddleware', 
'django.middleware.csrf.CsrfViewMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
'django.contrib.messages.middleware.MessageMiddleware', 
'django.middleware.clickjacking.XFrameOptionsMiddleware') 


Traceback: 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/core/handlers/base.py" in get_response 
    114.      response = wrapped_callback(request, *callback_args, **callback_kwargs) 
File "/home/hussain/django/ali/ali/views.py" in HomePage 
    6.  print " form :: ",form 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/utils/encoding.py" in <lambda> 
    60.   klass.__str__ = lambda self: self.__unicode__().encode('utf-8') 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/forms/forms.py" in __str__ 
    103.   return self.as_table() 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/forms/forms.py" in as_table 
    223.    errors_on_separate_row = False) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/forms/forms.py" in _html_output 
    186.      'field': six.text_type(bf), 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/forms/forms.py" in __str__ 
    425.   return self.as_widget() 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/forms/forms.py" in as_widget 
    475.   return widget.render(name, self.value(), attrs=attrs) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/forms/widgets.py" in render 
    572.   options = self.render_options(choices, value) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/forms/widgets.py" in render_options 
    528.   for option_value, option_label in chain(self.choices, choices): 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/forms/models.py" in __iter__ 
    1044.    for obj in self.queryset.all(): 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/models/query.py" in __iter__ 
    96.   self._fetch_all() 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/models/query.py" in _fetch_all 
    854.    self._result_cache = list(self.iterator()) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/models/query.py" in iterator 
    220.   for row in compiler.results_iter(): 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/models/sql/compiler.py" in results_iter 
    710.   for rows in self.execute_sql(MULTI): 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/models/sql/compiler.py" in execute_sql 
    781.   cursor.execute(sql, params) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/backends/util.py" in execute 
    69.    return super(CursorDebugWrapper, self).execute(sql, params) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/backends/util.py" in execute 
    53.     return self.cursor.execute(sql, params) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/utils.py" in __exit__ 
    99.     six.reraise(dj_exc_type, dj_exc_value, traceback) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/backends/util.py" in execute 
    53.     return self.cursor.execute(sql, params) 
File "/usr/local/lib/python2.7/dist-packages/Django-1.6.1-py2.7.egg/django/db/backends/sqlite3/base.py" in execute 
    450.   return Database.Cursor.execute(self, query, params) 

Exception Type: OperationalError at /home/ 
Exception Value: no such table: django_site 
+0

那么追溯显示你没有可能创建数据库某种数据库表,因为它明确指出:没有这样的表:django_site –

回答

2

没有为该项目: https://github.com/aljosa/django-tinymce

基本上你下载projcect,下载TinyMCE的。将tinymce文件添加到您的模板中,然后按照django-tinymce项目中的配置教程进行操作。

+0

Yitsaeb我需要一点帮助。 我正在按照文档,但在这里http://django-tinymce.readthedocs.org/en/latest/usage.html#python-code得到一个错误阅读'异常值:\t name'ModelForm'is not defined'你有什么主意吗 ? – Nagri

+0

不是没有看到更多的代码。你有代码中需要的代码需要的进口吗?这个错误指的是你没有从django导入forms.ModelForm。 –

+0

奥夫如果我已更新我的问题。 – Nagri