【发布时间】:2018-09-19 13:10:02
【问题描述】:
我想通过一个应用程序在网页上创建一个插件,但是,当将插件加载到页面时不会加载它的内容,而是在应用程序的页面上加载应用程序的内容.我认为问题可能出在插件定义的代码或模板中,我尝试了此链接中的建议http://docs.django-cms.org/en/latest/how_to/custom_plugins.html#handling-relations,但它不起作用只是运行错误。
应用程序是:https://github.com/tomwalker/django_quiz/tree/master/quiz
我一直在使用 python 3.4、django 1.8、djangoCMS 3.5
this is how the plugin content is displayed
This is how it should look, this is the content of the application
这是models.py的代码
from django.db import models
from cms.models import CMSPlugin
from quiz.models import Quiz, Question
class QuizPluginModel(CMSPlugin):
quiz = models.ForeignKey(Quiz)
def __unicode__(self):
return self.quiz.question
这是cms_plugins.py的代码
from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from quiz_cms_integration.models import QuizPluginModel, QuestionPluginModel
from django.utils.translation import gettext as _
@plugin_pool.register_plugin # register the plugin
class QuizPluginPublisher(CMSPluginBase):
model = QuizPluginModel # model where plugin data are saved
module = _("Quiz")
name = _("Quiz Plugin") # name of the plugin in the interface
render_template = "quiz_cms_integrations/quiz_list.html"
def render(self, context, instance, placeholder):
context.update({'instance': instance})
return context
这是一个模板 /quiz_list.html
{% extends 'base_q.html' %}
{% load i18n %}
{% block title %}{% trans "All Quizzes" %}{% endblock %}
{% block content %}
<h2>{% trans "List of quizzes" %}</h2>
{% if quiz_list %}
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>{% trans "Title" %}</th>
<th>{% trans "Category" %}</th>
<th>{% trans "Exam" %}</th>
<th>{% trans "Single attempt" %}</th>
<th></th>
</tr>
</thead>
<tbody>
{% for quiz in quiz_list %}
<tr>
<td>{{ quiz.title }}</td>
<td>{{ quiz.category }}</td>
<td>{{ quiz.exam_paper }}</td>
<td>{{ quiz.single_attempt }}</td>
<td>
<a href="{% url 'quiz_start_page' slug=quiz.url %}">
{% trans "View details" %}
</a>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>{% trans "There are no available quizzes" %}.</p>
{% endif %}
{% endblock %}
【问题讨论】:
标签: python django plugins django-templates django-cms