开发者

Repopulate django form

Wanted effect is passing the id to the request handler and populating the form with that entity. How doable is it with a template? Here are my form, request handler and template

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>


You should initialize your form with the entity you want to show:

form = AForm(instance = some_model_instance)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜