English 中文(简体)
Django模板和看法
原标题:Django templates and views

我在这里就座。 我正简单地将网站从html转换成一个Django驱动的网站,网站没有特殊内容,没有特别内容,有3页(cv/about/projects),并且是网络组合的范畴。

I want to use CKEditor to enable editing of the pages via the admin interface. I also want to be able to use the Django templates.

当从CK-edit-interface上页并增加内容时,我无法作为模板查阅网页。

我认为,守则对我的问题很重要:

模式:

from django.db import models
from ckeditor.fields import HTMLField

class Page(models.Model):
  title =  models.CharField(max_length=30)
  content = HTMLField(blank=True, verbose_name= HTML version )
  def __unicode__(self):
      return self.title

意见:

def cv(request):
  cv = Page.objects.filter(id=2)
  content = ([p.content for p in cv])
      return HttpResponse(content)

urls.py:

url(r ^cv$ , cv),

我阅读了背景和内容;使用模板使页数动态的载体,因此我写道:

意见:

from django.template import Context, loader

def about(request):
  about = Page.objects.filter(id=1)
  t = loader.get_template( about.html )
  ct = Context({
   about : about
  })
  return HttpResponse(t.render(ct))

但是,我需要通过各自的档案更新这些网页,而CKEdit-interface的网页没有reach。 任何人都知道我需要做些什么,并且能够利用Django模板编辑我的网页? (Using the{%/2005/4 content %}{% endblock %} ) While 仍然能够利用CKEditor编辑这些网页的内容。

问题回答

如果你扩大一些基础模板,即“基地.html”,那么我想:

基础:html

<html>
    <body>
    {% block header %}
        My header
    {% endblock header %}
    {% block content %}
        My content
    {% endblock content %}
    </body>
</html>

页: 1

{% extends "基础:html" %}

{% block content %}
    {{ about.content }}
{% endblock content %}

You passed the about context variable to 页: 1, so you need to call that variable. Basically, your templates cannot be completely empty. Even if 页: 1 contained nothing more than {{ about.content }}. I don t think you have given enough information to determine the part about CKE, but first start by making sure you can render something, anything, to the template, then tackle CKE





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...