在django中使用couchdbkit访问couchdb表单

时间:2012-12-31 18:18:57

标签: django forms couchdbkit

我能够成功地从couchdbkit form django extension

重现问候语示例

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

例外值:
没有 异常位置:/usr/lib/python2.7/site-packages/couchdbkit/schema/util.py in wrap,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

这是我的views.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")

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

0 个答案:

没有答案