重新填充django表格

时间:2010-09-12 02:16:18

标签: django google-app-engine django-forms django-templates

通缉效果是将id传递给请求处理程序并使用该实体填充表单。模板的可行性如何?这是我的表单,请求处理程序和模板

class AForm(djangoforms.ModelForm):  
  text = forms.CharField(widget=forms.Textarea(attrs={'rows':'11','cols':'70','class':'foo'}),label=_("content").capitalize())
  class Meta:
        model = A
        fields = ['category','currency','price','title','phonenumber','postaladress','name','text','email'] #change the order


class FileUploadFormHandler(I18NHandler):
  def get(self):
    cookie_django_language = self.request.get('hl', '') 
    if cookie_django_language:
      if cookie_django_language == 'unset':
        del self.request.COOKIES['django_language']
      else:
        self.request.COOKIES['django_language'] = cookie_django_language
        translation.activate(cookie_django_language)   
    self.render_template("upload.html", {
        'form': AForm(),
        'form_url': blobstore.create_upload_url('/fileupload'),
        'logout_url': users.create_logout_url('/'),
    })


 <table>
{% for field in form %}
<tr><td>
    <div class="fieldWrapper">
        {{ form.title.errors }}
        <label for="id_subject">{% filter capfirst %}{% trans "headline" %}{% endfilter %}</label></td><td>
        {{ form.title }}</td></tr>
    </div><tr><td>
    <div class="fieldWrapper">
        {{ form.category.errors }}
        <label for="id_subject">{% filter capfirst %}{% trans "content" %}{% endfilter %}</label></td><td>

1 个答案:

答案 0 :(得分:3)

您应该使用要显示的实体初始化表单:

form = AForm(instance = some_model_instance)