2

当我访问我的网址时,我只得到:<django.forms.fields.ChoiceField object at 0x026D1CD0> 我想要数字 Choicefield

我的models.py应用程序中有以下内容:

from django.db import models
from django.forms import ModelForm

class Zonas(models.Model):
    name = models.CharField(max_length=30)

    def __unicode__(self):
    return self.name

class ZonasForm(ModelForm):
    class Meta:
       model = Zonas

我想问题出在我的views.py

from django    import forms
from testApp.models import Zonas
from django.shortcuts import render_to_response

def menuForm (request):
    z = list (Zonas.objects.all())
    numbers = forms.ChoiceField(z)
    return render_to_response('hello.html', {'numbers':numbers})

menuForm 用于我urls.py的 as:

from django.conf.urls import patterns, include, url
from testApp.views import menuForm
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',

url(r'^hello/$', menuForm ),
)

我的html页面尽可能简单:

<html>
<body>

{{numbers}}

</body>
</html>

任何帮助表示赞赏

4

1 回答 1

2

您的页面网址不正确,请将其更改为

url(r'^hello/$', menuForm),

文档中所述,它的形式为

(正则表达式,Python 回调函数 [, optional_dictionary [, optional_name]])

此外,将视图函数的定义更改为

def menuForm (request):
....
于 2013-04-30T11:36:36.040 回答