FAQ
Hello,

I'm trying to create simple method to create category. I set the model
category:

class Category(db.Model):
title = db.StringProperty(required=True)
clashes_count = db.IntegerProperty(default=0)

And the class New Category as well :

class NewCategoryPage(webapp.RequestHandler):
def get(self):
categories = Category.all().order('-title')

template_values = { }
path = os.path.join(os.path.dirname(__file__), 'templates',
'category_new.html')
self.response.out.write(template.render(path, template_values))

def post(self):
category = Category()
category.title = self.request.get('title')
category.put()
self.redirect('/')

Here is the template:

{%extends "base.html"%}
{%block body%}

<h2>Add New Category</h2>

<form action="" method="post">
<div>Title: <input type="text" name="title" size="100" /></div>
<div><input type="submit" value="Publish"></div>
</form>

{%endblock%}

The problem is that I'm getting an error BadValueError: Property title
is required. Can you help me with that ? Thanks

Search Discussions

  • Chris Rebert at May 31, 2011 at 8:32 am

    On Tue, May 31, 2011 at 1:21 AM, michal.bulla wrote:
    Hello,

    I'm trying to create simple method to create category. I set the model
    category:

    class Category(db.Model):
    ?title = db.StringProperty(required=True)
    ?clashes_count = db.IntegerProperty(default=0)
    <snip some obviously Django-using code>
    The problem is that I'm getting an error BadValueError: Property title
    is required. Can you help me with that ? Thanks
    Try asking on the Django mailing list:
    http://groups.google.com/group/django-users

    Cheers,
    Chris
  • Bruno Desthuilliers at May 31, 2011 at 2:28 pm

    On May 31, 10:32?am, Chris Rebert wrote:
    On Tue, May 31, 2011 at 1:21 AM, michal.bulla wrote:
    Hello,
    I'm trying to create simple method to create category. I set the model
    category:
    class Category(db.Model):
    ?title = db.StringProperty(required=True)
    ?clashes_count = db.IntegerProperty(default=0)
    <snip some obviously Django-using code>
    Not "obviously" Django at all.
    The problem is that I'm getting an error BadValueError: Property title
    is required. Can you help me with that ? Thanks
    Try asking on the Django mailing list:http://groups.google.com/group/django-users
    Arf ! I just told the guy he was on the wrong group when he
    (re?)posted this on django-users.
  • Casey Dwyer at Jun 3, 2011 at 4:53 pm

    On May 31, 1:21?am, "michal.bulla" wrote:
    Hello,

    I'm trying to create simple method to create category. I set the model
    category:

    class Category(db.Model):
    ? title = db.StringProperty(required=True)
    ? clashes_count = db.IntegerProperty(default=0)

    And the class New Category as well :

    class NewCategoryPage(webapp.RequestHandler):
    ? def get(self):
    ? ? categories = Category.all().order('-title')

    ? ? template_values = { }
    ? ? path = os.path.join(os.path.dirname(__file__), 'templates',
    'category_new.html')
    ? ? self.response.out.write(template.render(path, template_values))

    ? def post(self):
    ? ? category = Category()
    ? ? category.title = self.request.get('title')
    ? ? category.put()
    ? ? self.redirect('/')

    Here is the template:

    {%extends "base.html"%}
    {%block body%}

    <h2>Add New Category</h2>

    <form action="" method="post">
    ? <div>Title: <input type="text" name="title" size="100" /></div>
    ? <div><input type="submit" value="Publish"></div>
    </form>

    {%endblock%}

    The problem is that I'm getting an error BadValueError: Property title
    is required. Can you help me with that ? Thanks
    Required properties must be declared in the constructor. Try this
    instead:

    category = Category(title=self.request.get('title'))
    category.put()

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedMay 31, '11 at 8:21a
activeJun 3, '11 at 4:53p
posts4
users4
websitepython.org

People

Translate

site design / logo © 2022 Grokbase