3

我能够从couchdbkit 表单 django 扩展成功地重现问候示例

但是,我基本上复制了相同的示例以使用名为 projects 的现有 couchdb 数据库,但出现以下错误:

异常值:
无异常位置:/usr/lib/python2.7/site-packages/couchdbkit/schema/util.py in wrap, line 29 所以我想知道是什么造成了这个异常

这是我的models.py

from django.db import models
# Create your models here.
from couchdbkit.ext.django.schema import *
from couchdbkit.ext.django.forms import *
from datetime import datetime
from couchdbkit import Document
from couchdbkit import *
from couchdbkit.ext.django.forms  import DocumentForm
from couchdbkit.ext.django.forms  import *
class project(Document):
    name = StringProperty()
    type = StringProperty(required=True,default="project")
    created_at = DateTimeProperty(default=datetime.utcnow)

这是我的forms.py

from django.db import models
# Create your form here.
from couchdbkit.ext.django.schema import *
from couchdbkit.ext.django.forms import *
from datetime import datetime
from couchdbkit import Document
from couchdbkit import *
from couchdbkit.ext.django.forms  import DocumentForm
from couchdbkit.ext.django.forms  import *
class projectForm(DocumentForm):    
     class Meta:
         document = project

这是我的意见.py

# Create your views here.
from django.shortcuts import render_to_response as render
from django.shortcuts import render_to_response
from django.http import HttpResponse
from datetime import datetime
from couchdbkit import Document
from couchdbkit import *
from couchdbkit.ext.django.forms  import DocumentForm
from couchdbkit.ext.django.forms  import *
from django import forms
from django.template import Context, Template
from django.template import RequestContext, loader, Context
from django.http import HttpResponseRedirect
from projects.models import project
from projects.models import Building
from couchdbkit.ext.django.loading import get_db

db = get_db('projects')
class projectForm(DocumentForm):    
    class Meta:
        document = project
class BuildingForm(DocumentForm):    
     class Meta:
         document = Building
def home(request):
    project.set_db(db) 
    greet = None
    if request.POST:
        form = projectForm(request.POST)
        if form.is_valid():
            greet = form.save()
            return render_to_response('dbcontent.html',{'row':db})
    else:
        form = projectForm()
    projects = project.view("projects/all")
    return render("home.html", {
        "form": form,
        "greet": greet,
        "projects": projects,
    }, context_instance=RequestContext(request))

这是我的 home.html

{% extends "base.html" %}
{% load i18n %} 
{% block content %}
            <form contact="/project/" method="post"> {% csrf_token %}
                <table>
                {{ form.as_table }}
                </table>
                <input type="submit" id="submit" value="submit">
            </form>
            {% if greet %}
            {{ greet.get_id }} was added
            {% endif %}
            <h2>Projects</h2>
            <table>
            {% for p in projects %}
                <tr>
                    <td>{{ p.timestamp|timesince }} </td>
                    <td>{{ p.name }} </td>
                    <td>{{ p.type }}</td>
                </tr>
            {% endfor %}
            </table>
        {% endblock content %}

所以 Django 将我 home.html 上的以下行索引为异常的起源

{% for p in projects %}

并给我上面提到的错误。

但是请注意,在我的 home.html 中,如果我替换{% for p in projects %}{% for p in home %}错误消失了,但只显示了表单,并且没有从 couchdb 检索数据

我非常有信心在我看来这个错误与这个陈述有关 projects = project.view("projects/all")

那么我在这里错过了什么?提前致谢,如果您在我的声明中看到一些冗余,我深表歉意。

4

0 回答 0