我有現有的夾層項目與現有的頁面。可以實現AdminPage流暢內容功能而不具有流暢頁面功能?只是想創建夾層頁面,但內容流暢。這可能實現嗎?任何人都可以展示一些如何實現它到Mezzanine AdminPage的例子。如何實現django流利的內容到夾層現有項目
回答
由於沒有人有這個問題,我已經弄清楚,併成功實現流利內容到現有的夾層項目。 這很簡單,但調查需要編輯夾層cms的核心來源。畢竟輸出解決方案是簡單的應用程序,擴展夾層頁面在管理員或客戶端。
(難度:媒體/專家)
SOLUTION:
(在這個例子中我已經使用的應用程序名稱爲 「cms_coremodul」) PS:有人用版本製作。 Python 3.4與虛擬環境。
閣設置並安裝:
夾層4.0.1
-install流暢,內容不同,需要 (遵循fluent-contents docs)什麼期望插件-version。
pip install django-fluent-contents
- 也可以選擇安裝功能強大的wysiwyg CKEditor。
pip install django-ckeditor
-所有安裝後,讓我們轉到setup settings.py並將所有內容遷移。
settings.py:
-fluent,內容必須高於你的應用程序及以下夾層應用程序。
INSTALLED_APPS = (
...
"fluent_contents",
"django_wysiwyg",
"ckeditor",
# all working fluent-contents plugins
'fluent_contents.plugins.text', # requires django-wysiwyg
'fluent_contents.plugins.code', # requires pygments
'fluent_contents.plugins.gist',
'fluent_contents.plugins.iframe',
'fluent_contents.plugins.markup',
'fluent_contents.plugins.rawhtml',
'fluent_contents.plugins.picture',
'fluent_contents.plugins.oembeditem',
'fluent_contents.plugins.sharedcontent',
'fluent_contents.plugins.googledocsviewer',
...
'here_will_be_your_app',
)
-settings爲Django的CKEditor的:
settings.py:
# CORE MODUL DEFAULT WYSIWYG EDITOR SETUP
RICHTEXT_WIDGET_CLASS = "ckeditor.widgets.CKEditorWidget"
RICHTEXT_FILTER_LEVEL = 3
DJANGO_WYSIWYG_FLAVOR = "ckeditor"
# CKEditor config
CKEDITOR_CONFIGS = {
'awesome_ckeditor': {
'toolbar': 'Full',
},
'default': {
'toolbar': 'Standard',
'width': '100%',
},
}
的流暢,內容是完整的settings.py的-after設置允許遷移了一切:
python manage.py migrate
- 如果會出現關於流利內容依賴關係的任何錯誤/錯誤,請安裝該依賴項並再次遷移。
製作新的應用FOR FLUENT-內容:
創建夾層項目的新的應用程序(相同的Django):
蟒蛇manage.py的startApp nameofyourapp
models.py:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from mezzanine.pages.models import Page
from django.utils.translation import ugettext_lazy as _
from fluent_contents.models import PlaceholderRelation, ContentItemRelation
from mezzanine.core.fields import FileField
from . import appconfig
class CoreModulPage(Page):
template_name = models.CharField("Template choice", max_length=255, choices=appconfig.TEMPLATE_CHOICES, default=appconfig.COREMODUL_DEFAULT_TEMPLATE)
# Accessing the data of django-fluent-contents
placeholder_set = PlaceholderRelation()
contentitem_set = ContentItemRelation()
class Meta:
verbose_name = _("Core page")
verbose_name_plural = _("Core pages")
admin.py:
from django.contrib import admin
from django.http.response import HttpResponse
from mezzanine.pages.admin import PageAdmin
import json
# CORE MODUL IMPORT
from fluent_contents.admin import PlaceholderEditorAdmin
from fluent_contents.analyzer import get_template_placeholder_data
from django.template.loader import get_template
from .models import CoreModulPage
from . import appconfig
from fluent_contents.admin.placeholdereditor import PlaceholderEditorInline
class CoreModulAdmin(PlaceholderEditorAdmin, PageAdmin):
#################################
#CORE MODUL - PAGE LOGIC
#################################
corepage = CoreModulPage.objects.all()
# CORE FLUENT-CONTENTS
# This is where the magic happens.
# Tell the base class which tabs to create
def get_placeholder_data(self, request, obj):
# Tell the base class which tabs to create
template = self.get_page_template(obj)
return get_template_placeholder_data(template)
def get_page_template(self, obj):
# Simple example that uses the template selected for the page.
if not obj:
return get_template(appconfig.COREMODUL_DEFAULT_TEMPLATE)
else:
return get_template(obj.template_name or appconfig.COREMODUL_DEFAULT_TEMPLATE)
# Allow template layout changes in the client,
# showing more power of the JavaScript engine.
# THIS LINES ARE OPTIONAL
# It sets your own path to admin templates and static of fluent-contents
#
# START OPTIONAL LINES
# this "PlaceholderEditorInline.template" is in templates folder of your app
PlaceholderEditorInline.template = "cms_plugins/cms_coremodul/admin/placeholder/inline_tabs.html"
# this "PlaceholderEditorInline.Media.js"
# and "PlaceholderEditorInline.Media.css" is in static folder of your app
PlaceholderEditorInline.Media.js = (
'cms_plugins/cms_coremodul/admin/js/jquery.cookie.js',
'cms_plugins/cms_coremodul/admin/js/cp_admin.js',
'cms_plugins/cms_coremodul/admin/js/cp_data.js',
'cms_plugins/cms_coremodul/admin/js/cp_tabs.js',
'cms_plugins/cms_coremodul/admin/js/cp_plugins.js',
'cms_plugins/cms_coremodul/admin/js/cp_widgets.js',
'cms_plugins/cms_coremodul/admin/js/fluent_contents.js',
)
PlaceholderEditorInline.Media.css = {
'screen': (
'cms_plugins/cms_coremodul/admin/css/cp_admin.css',
),
}
PlaceholderEditorInline.extend = False # No need for the standard 'admin/js/inlines.min.js' here.
#
# END OPTIONAL LINES
# template to change rendering template for contents (combobox in page to choose desired template to render)
change_form_template = "cms_plugins/cms_coremodul/admin/page/change_form.html"
class Media:
js = (
'cms_plugins/cms_coremodul/admin/js/coremodul_layouts.js',
)
def get_layout_view(self, request):
"""
Return the metadata about a layout
"""
template_name = request.GET['name']
# Check if template is allowed, avoid parsing random templates
templates = dict(appconfig.TEMPLATE_CHOICES)
if not templates.has_key(template_name):
jsondata = {'success': False, 'error': 'Template was not found!'}
status = 404
else:
# Extract placeholders from the template, and pass to the client.
template = get_template(template_name)
placeholders = get_template_placeholder_data(template)
jsondata = {
'placeholders': [p.as_dict() for p in placeholders],
}
status = 200
jsonstr = json.dumps(jsondata)
return HttpResponse(jsonstr, content_type='application/json', status=status)
admin.site.register(CoreModulPage, CoreModulAdmin)
appconfig.py:
- 你在你的應用程序來創建新appconfig.py文件。
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
TEMPLATE_CHOICES = getattr(settings, "TEMPLATE_CHOICES",())
COREMODUL_DEFAULT_TEMPLATE = getattr(settings, "COREMODUL_DEFAULT_TEMPLATE", TEMPLATE_CHOICES[0][0] if TEMPLATE_CHOICES else None)
if not TEMPLATE_CHOICES:
raise ImproperlyConfigured("Value of variable 'TEMPLATE_CHOICES' is not set!")
if not COREMODUL_DEFAULT_TEMPLATE:
raise ImproperlyConfigured("Value of variable 'COREMODUL_DEFAULT_TEMPLATE' is not set!")
settings.py: - 此行添加到您的settings.py夾層項目。
# CORE MODUL TEMPLATE LIST
TEMPLATE_CHOICES = (
("pages/coremodulpage.html", "CoreModulPage"),
("pages/coremodulpagetwo.html", "CoreModulPage2"),
)
# CORE MODUL default template setup (if drop-down not exist in admin interface)
COREMODUL_DEFAULT_TEMPLATE = TEMPLATE_CHOICES[0][0]
- 將您的應用程序擴展到INSTALLED_APPS(將您的應用程序添加到INSTALLED_APPS)。
INSTALLED_APPS = (
...
"yourappname_with_fluentcontents",
)
爲您您的應用程序的內容創建模板:
-template一個佔位符:
coremodulpage.html:
{% extends "pages/page.html" %}
{% load mezzanine_tags fluent_contents_tags %}
{% block main %}{{ block.super }}
{% page_placeholder page.coremodulpage "main" role='m' %}
{% endblock %}
-template有兩個佔位符(一邊):
{% extends "pages/page.html" %}
{% load mezzanine_tags fluent_contents_tags %}
{% block main %}{{ block.super }}
{% page_placeholder page.coremodulpage "main" role='m' %}
<aside>
{% page_placeholder page.coremodulpage "sidepanel" role='s' %}
</aside>
{% endblock %}
-after您的應用程序設置可以讓使遷移:
-1.Make您的應用程序遷移:
python manage.py makemigrations yourappname
-2.Make您的應用程序遷移到數據庫:
python manage.py migrate
FINALY COMPLETE! - 嘗試使用安裝了Fluent內容插件的新類型管理頁面。 - 在Admin的頁面類型下拉列表中,選擇核心頁面。如果您已經創建了模板以呈現帶有下拉框的佔位符顯示的流暢內容選項卡。現在您可以選擇所需的插件並創建頁面的模塊化內容。
- 1. 在現有的Django項目中集成夾層
- 2. 我在哪裏可以找到現有夾層項目的SECRET_KEY?
- 3. django實現未讀項目
- 4. 將MVVM實現到現有項目中
- 5. 加入jQuery的內容裝載到現有股利內容
- 6. 如何順利添加內容到現有的PDF文檔?
- 7. ACRA - 如何實現它到一個現有的項目
- 8. 實現現有項目的Maven
- 9. 如何刪除現有TFS文件夾的所有內容並簽入同一文件夾中的新項目?
- 10. 在現有項目上實現Git
- 11. 實現OnClickListener到ListView項目
- 12. 如何在現有的Web項目上實現翻譯?
- 13. 如何在現有的WindowBuilder項目中實現JavaFX?
- 14. 實現Chart.js插件流星項目
- 15. 如何開始將django-cms集成到現有項目中
- 16. Mootools:如何將項目添加到現有的Fx.Sort實例
- 17. 在流利的NHibernate中插入一個有現有子項的父實體
- 18. 如何實現業務層
- 19. 只有在Django的現有項目只讀內聯
- 20. 如何在Django項目的Tastypie中實現登錄模塊
- 21. 有沒有流利的WPF項目?
- 22. 如何實現在CruiseControl的Flex項目
- 23. 如何實現重複項目的ListView?
- 24. 實現沒有內容失真的slideUp()
- 25. 利用現有的收集流星
- 26. 項目Darkstar現實?
- 27. 有沒有辦法讓定製內容與夾層/ Django
- 28. 如何實現以下內容?
- 29. 如何在工作流星項目上實現Collection2?
- 30. 如何將現有項目更新到實體框架5.0