librelist archives

« back to archive

Need help with an (database?) error

Need help with an (database?) error

From:
Samrat Man Singh
Date:
2011-07-18 @ 10:32
I've tried to write a very simple blog-engine-

from flask import Flask, render_template
>
> import default_settings
>
> from flaskext.sqlalchemy import SQLAlchemy
>
>
>> app = Flask(__name__)
>
> app.config.from_pyfile('default_settings.py')
>
> db = SQLAlchemy(app)
>
>
>> class Post(db.Model):
>
>     id = db.Column(db.Integer, primary_key = True)
>
>     title = db.Column(db.String(255))
>
>     post_body = db.Column(db.Text)
>
>
>
>     def __init__(self):
>
>         self.id = id
>
>         self.title = title
>
>         self.post_body = post_body
>
>
>> def initdb():
>
>     db.create_all()
>
>     print "Initialized new empty database in %s" %
>> app.config['SQLALCHEMY_DATABASE_URI']
>
>
>
>
>>
>
> '''class Admin(db.Model):
>
>     id = db.Column(db.Integer, primary_key = True)
>
>     username = db.Column(db.String(255))
>
>     password = db.Column(db.String(255))
>
> '''
>
>
>> @app.route('/compose', methods = ['POST', 'GET'])
>
> def compose():
>
>     if request.method == 'GET':
>
>         return render_template('compose.html')
>
>
>
>     title = request.form['title']
>
>     post_body = request.form['post_body']
>
>
>
>     if request.form['action'] == 'Publish':
>
>         post = Post(title, body)
>
>         db.session.add(post)
>
>         db.session.commit()
>
>
>
> @app.route('/')
>
> def index():
>
>     posts = Post.query
>
>     return render_template('posts.html', posts = posts)
>
>
>
> if __name__ == '__main__':
>
>     app.run()
>
>
>
(I don't know where the problem really is so I've included the whole code
here)

The application runs but when I open it on the local server it shows the
following error:

SELECT post.id AS post_id, post.title AS post_title, post.post_body AS
post_post_body FROM post

I tried a few things like reinitializing the database, but that didn't
really seem to help. Can someone help me with this please?


Samrat

Re: [flask] Need help with an (database?) error

From:
Ishbir Singh
Date:
2011-07-18 @ 14:27
Hey,

Fault is in-
*posts = Post.query*
Try replacing this with-
*posts = Post.query.all()*

On 18 July 2011 16:02, Samrat Man Singh <samratmansingh@gmail.com> wrote:

> I've tried to write a very simple blog-engine-
>
>  from flask import Flask, render_template
>>
>> import default_settings
>>
>> from flaskext.sqlalchemy import SQLAlchemy
>>
>>
>>> app = Flask(__name__)
>>
>> app.config.from_pyfile('default_settings.py')
>>
>> db = SQLAlchemy(app)
>>
>>
>>> class Post(db.Model):
>>
>>     id = db.Column(db.Integer, primary_key = True)
>>
>>     title = db.Column(db.String(255))
>>
>>     post_body = db.Column(db.Text)
>>
>>
>>
>>     def __init__(self):
>>
>>         self.id = id
>>
>>         self.title = title
>>
>>         self.post_body = post_body
>>
>>
>>> def initdb():
>>
>>     db.create_all()
>>
>>     print "Initialized new empty database in %s" %
>>> app.config['SQLALCHEMY_DATABASE_URI']
>>
>>
>>
>>
>>>
>>
>> '''class Admin(db.Model):
>>
>>     id = db.Column(db.Integer, primary_key = True)
>>
>>     username = db.Column(db.String(255))
>>
>>     password = db.Column(db.String(255))
>>
>> '''
>>
>>
>>> @app.route('/compose', methods = ['POST', 'GET'])
>>
>> def compose():
>>
>>     if request.method == 'GET':
>>
>>         return render_template('compose.html')
>>
>>
>>
>>     title = request.form['title']
>>
>>     post_body = request.form['post_body']
>>
>>
>>
>>     if request.form['action'] == 'Publish':
>>
>>         post = Post(title, body)
>>
>>         db.session.add(post)
>>
>>         db.session.commit()
>>
>>
>>
>> @app.route('/')
>>
>> def index():
>>
>>     posts = Post.query
>>
>>     return render_template('posts.html', posts = posts)
>>
>>
>>
>> if __name__ == '__main__':
>>
>>     app.run()
>>
>>
>>
> (I don't know where the problem really is so I've included the whole code
> here)
>
> The application runs but when I open it on the local server it shows the
> following error:
>
> SELECT post.id AS post_id, post.title AS post_title, post.post_body AS
> post_post_body FROM post
>
> I tried a few things like reinitializing the database, but that didn't
> really seem to help. Can someone help me with this please?
>
>
> Samrat
>



-- 
Regards,
Ishbir Singh

Re: [flask] Need help with an (database?) error

From:
Samrat Man Singh
Date:
2011-07-18 @ 15:00
Thanks, the problem got solved but I got another error on this line- post =
Post(title, post_body) and I'm not sure why. This is the error I got-

TypeError: __init__() takes exactly 1 argument (3 given)

Samrat

On Mon, Jul 18, 2011 at 8:12 PM, Ishbir Singh <webmaster@ishbir.com> wrote:

> Hey,
>
> Fault is in-
> *posts = Post.query*
> Try replacing this with-
> *posts = Post.query.all()*
>
> On 18 July 2011 16:02, Samrat Man Singh <samratmansingh@gmail.com> wrote:
>
>> I've tried to write a very simple blog-engine-
>>
>>  from flask import Flask, render_template
>>>
>>> import default_settings
>>>
>>> from flaskext.sqlalchemy import SQLAlchemy
>>>
>>>
>>>> app = Flask(__name__)
>>>
>>> app.config.from_pyfile('default_settings.py')
>>>
>>> db = SQLAlchemy(app)
>>>
>>>
>>>> class Post(db.Model):
>>>
>>>     id = db.Column(db.Integer, primary_key = True)
>>>
>>>     title = db.Column(db.String(255))
>>>
>>>     post_body = db.Column(db.Text)
>>>
>>>
>>>
>>>     def __init__(self):
>>>
>>>         self.id = id
>>>
>>>         self.title = title
>>>
>>>         self.post_body = post_body
>>>
>>>
>>>> def initdb():
>>>
>>>     db.create_all()
>>>
>>>     print "Initialized new empty database in %s" %
>>>> app.config['SQLALCHEMY_DATABASE_URI']
>>>
>>>
>>>
>>>
>>>>
>>>
>>> '''class Admin(db.Model):
>>>
>>>     id = db.Column(db.Integer, primary_key = True)
>>>
>>>     username = db.Column(db.String(255))
>>>
>>>     password = db.Column(db.String(255))
>>>
>>> '''
>>>
>>>
>>>> @app.route('/compose', methods = ['POST', 'GET'])
>>>
>>> def compose():
>>>
>>>     if request.method == 'GET':
>>>
>>>         return render_template('compose.html')
>>>
>>>
>>>
>>>     title = request.form['title']
>>>
>>>     post_body = request.form['post_body']
>>>
>>>
>>>
>>>     if request.form['action'] == 'Publish':
>>>
>>>         post = Post(title, body)
>>>
>>>         db.session.add(post)
>>>
>>>         db.session.commit()
>>>
>>>
>>>
>>> @app.route('/')
>>>
>>> def index():
>>>
>>>     posts = Post.query
>>>
>>>     return render_template('posts.html', posts = posts)
>>>
>>>
>>>
>>> if __name__ == '__main__':
>>>
>>>     app.run()
>>>
>>>
>>>
>> (I don't know where the problem really is so I've included the whole code
>> here)
>>
>> The application runs but when I open it on the local server it shows the
>> following error:
>>
>> SELECT post.id AS post_id, post.title AS post_title, post.post_body AS
>> post_post_body FROM post
>>
>> I tried a few things like reinitializing the database, but that didn't
>> really seem to help. Can someone help me with this please?
>>
>>
>> Samrat
>>
>
>
>
> --
> Regards,
> Ishbir Singh
>
>

Re: [flask] Need help with an (database?) error

From:
Adam Patterson
Date:
2011-07-18 @ 15:04
class Post(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    title = db.Column(db.String(255))
    post_body = db.Column(db.Text)


    def __init__(self,):
        self.id = id
        self.title = title
        self.post_body = post_body

On Mon, Jul 18, 2011 at 10:00 AM, Samrat Man Singh
<samratmansingh@gmail.com> wrote:
> Thanks, the problem got solved but I got another error on this line- post =
> Post(title, post_body) and I'm not sure why. This is the error I got-
> TypeError: __init__() takes exactly 1 argument (3 given)
> Samrat
>
> On Mon, Jul 18, 2011 at 8:12 PM, Ishbir Singh <webmaster@ishbir.com> wrote:
>>
>> Hey,
>>
>> Fault is in-
>> posts = Post.query
>> Try replacing this with-
>> posts = Post.query.all()
>>
>> On 18 July 2011 16:02, Samrat Man Singh <samratmansingh@gmail.com> wrote:
>>>
>>> I've tried to write a very simple blog-engine-
>>>>>
>>>>> from flask import Flask, render_template
>>>>>
>>>>> import default_settings
>>>>>
>>>>> from flaskext.sqlalchemy import SQLAlchemy
>>>>>
>>>>> app = Flask(__name__)
>>>>>
>>>>> app.config.from_pyfile('default_settings.py')
>>>>>
>>>>> db = SQLAlchemy(app)
>>>>>
>>>>> class Post(db.Model):
>>>>>
>>>>>     id = db.Column(db.Integer, primary_key = True)
>>>>>
>>>>>     title = db.Column(db.String(255))
>>>>>
>>>>>     post_body = db.Column(db.Text)
>>>>>
>>>>>
>>>>>
>>>>>     def __init__(self):
>>>>>
>>>>>         self.id = id
>>>>>
>>>>>         self.title = title
>>>>>
>>>>>         self.post_body = post_body
>>>>>
>>>>> def initdb():
>>>>>
>>>>>     db.create_all()
>>>>>
>>>>>     print "Initialized new empty database in %s" %
>>>>> app.config['SQLALCHEMY_DATABASE_URI']
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> '''class Admin(db.Model):
>>>>>
>>>>>     id = db.Column(db.Integer, primary_key = True)
>>>>>
>>>>>     username = db.Column(db.String(255))
>>>>>
>>>>>     password = db.Column(db.String(255))
>>>>>
>>>>> '''
>>>>>
>>>>> @app.route('/compose', methods = ['POST', 'GET'])
>>>>>
>>>>> def compose():
>>>>>
>>>>>     if request.method == 'GET':
>>>>>
>>>>>         return render_template('compose.html')
>>>>>
>>>>>
>>>>>
>>>>>     title = request.form['title']
>>>>>
>>>>>     post_body = request.form['post_body']
>>>>>
>>>>>
>>>>>
>>>>>     if request.form['action'] == 'Publish':
>>>>>
>>>>>         post = Post(title, body)
>>>>>
>>>>>         db.session.add(post)
>>>>>
>>>>>         db.session.commit()
>>>>>
>>>>>
>>>>>
>>>>> @app.route('/')
>>>>>
>>>>> def index():
>>>>>
>>>>>     posts = Post.query
>>>>>
>>>>>     return render_template('posts.html', posts = posts)
>>>>>
>>>>>
>>>>>
>>>>> if __name__ == '__main__':
>>>>>
>>>>>     app.run()
>>>
>>> (I don't know where the problem really is so I've included the whole code
>>> here)
>>> The application runs but when I open it on the local server it shows the
>>> following error:
>>> SELECT post.id AS post_id, post.title AS post_title, post.post_body AS
>>> post_post_body FROM post
>>> I tried a few things like reinitializing the database, but that didn't
>>> really seem to help. Can someone help me with this please?
>>>
>>> Samrat
>>
>>
>> --
>> Regards,
>> Ishbir Singh
>
>

Re: [flask] Need help with an (database?) error

From:
Adam Patterson
Date:
2011-07-18 @ 15:06
sorry, accidentally sent that last message before i was ready

class Post(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    title = db.Column(db.String(255))
    post_body = db.Column(db.Text)

    # Add title, post_body to this
    def __init__(self, title, post_body):
        self.title = title
        self.post_body = post_body

also remove the self.id = id. that will be generated by your db.

On Mon, Jul 18, 2011 at 10:04 AM, Adam Patterson <fakeempire@gmail.com> wrote:
> class Post(db.Model):
>    id = db.Column(db.Integer, primary_key = True)
>    title = db.Column(db.String(255))
>    post_body = db.Column(db.Text)
>
>
>    def __init__(self,):
>        self.id = id
>        self.title = title
>        self.post_body = post_body
>
> On Mon, Jul 18, 2011 at 10:00 AM, Samrat Man Singh
> <samratmansingh@gmail.com> wrote:
>> Thanks, the problem got solved but I got another error on this line- post =
>> Post(title, post_body) and I'm not sure why. This is the error I got-
>> TypeError: __init__() takes exactly 1 argument (3 given)
>> Samrat
>>
>> On Mon, Jul 18, 2011 at 8:12 PM, Ishbir Singh <webmaster@ishbir.com> wrote:
>>>
>>> Hey,
>>>
>>> Fault is in-
>>> posts = Post.query
>>> Try replacing this with-
>>> posts = Post.query.all()
>>>
>>> On 18 July 2011 16:02, Samrat Man Singh <samratmansingh@gmail.com> wrote:
>>>>
>>>> I've tried to write a very simple blog-engine-
>>>>>>
>>>>>> from flask import Flask, render_template
>>>>>>
>>>>>> import default_settings
>>>>>>
>>>>>> from flaskext.sqlalchemy import SQLAlchemy
>>>>>>
>>>>>> app = Flask(__name__)
>>>>>>
>>>>>> app.config.from_pyfile('default_settings.py')
>>>>>>
>>>>>> db = SQLAlchemy(app)
>>>>>>
>>>>>> class Post(db.Model):
>>>>>>
>>>>>>     id = db.Column(db.Integer, primary_key = True)
>>>>>>
>>>>>>     title = db.Column(db.String(255))
>>>>>>
>>>>>>     post_body = db.Column(db.Text)
>>>>>>
>>>>>>
>>>>>>
>>>>>>     def __init__(self):
>>>>>>
>>>>>>         self.id = id
>>>>>>
>>>>>>         self.title = title
>>>>>>
>>>>>>         self.post_body = post_body
>>>>>>
>>>>>> def initdb():
>>>>>>
>>>>>>     db.create_all()
>>>>>>
>>>>>>     print "Initialized new empty database in %s" %
>>>>>> app.config['SQLALCHEMY_DATABASE_URI']
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> '''class Admin(db.Model):
>>>>>>
>>>>>>     id = db.Column(db.Integer, primary_key = True)
>>>>>>
>>>>>>     username = db.Column(db.String(255))
>>>>>>
>>>>>>     password = db.Column(db.String(255))
>>>>>>
>>>>>> '''
>>>>>>
>>>>>> @app.route('/compose', methods = ['POST', 'GET'])
>>>>>>
>>>>>> def compose():
>>>>>>
>>>>>>     if request.method == 'GET':
>>>>>>
>>>>>>         return render_template('compose.html')
>>>>>>
>>>>>>
>>>>>>
>>>>>>     title = request.form['title']
>>>>>>
>>>>>>     post_body = request.form['post_body']
>>>>>>
>>>>>>
>>>>>>
>>>>>>     if request.form['action'] == 'Publish':
>>>>>>
>>>>>>         post = Post(title, body)
>>>>>>
>>>>>>         db.session.add(post)
>>>>>>
>>>>>>         db.session.commit()
>>>>>>
>>>>>>
>>>>>>
>>>>>> @app.route('/')
>>>>>>
>>>>>> def index():
>>>>>>
>>>>>>     posts = Post.query
>>>>>>
>>>>>>     return render_template('posts.html', posts = posts)
>>>>>>
>>>>>>
>>>>>>
>>>>>> if __name__ == '__main__':
>>>>>>
>>>>>>     app.run()
>>>>
>>>> (I don't know where the problem really is so I've included the whole code
>>>> here)
>>>> The application runs but when I open it on the local server it shows the
>>>> following error:
>>>> SELECT post.id AS post_id, post.title AS post_title, post.post_body AS
>>>> post_post_body FROM post
>>>> I tried a few things like reinitializing the database, but that didn't
>>>> really seem to help. Can someone help me with this please?
>>>>
>>>> Samrat
>>>
>>>
>>> --
>>> Regards,
>>> Ishbir Singh
>>
>>
>

Re: [flask] Need help with an (database?) error

From:
Samrat Man Singh
Date:
2011-07-18 @ 15:29
Adam, thanks!!

On Mon, Jul 18, 2011 at 8:51 PM, Adam Patterson <fakeempire@gmail.com>wrote:

> sorry, accidentally sent that last message before i was ready
>
> class Post(db.Model):
>    id = db.Column(db.Integer, primary_key = True)
>    title = db.Column(db.String(255))
>    post_body = db.Column(db.Text)
>
>     # Add title, post_body to this
>    def __init__(self, title, post_body):
>         self.title = title
>        self.post_body = post_body
>
> also remove the self.id = id. that will be generated by your db.
>
> On Mon, Jul 18, 2011 at 10:04 AM, Adam Patterson <fakeempire@gmail.com>
> wrote:
> > class Post(db.Model):
> >    id = db.Column(db.Integer, primary_key = True)
> >    title = db.Column(db.String(255))
> >    post_body = db.Column(db.Text)
> >
> >
> >    def __init__(self,):
> >        self.id = id
> >        self.title = title
> >        self.post_body = post_body
> >
> > On Mon, Jul 18, 2011 at 10:00 AM, Samrat Man Singh
> > <samratmansingh@gmail.com> wrote:
> >> Thanks, the problem got solved but I got another error on this
> line- post =
> >> Post(title, post_body) and I'm not sure why. This is the error I got-
> >> TypeError: __init__() takes exactly 1 argument (3 given)
> >> Samrat
> >>
> >> On Mon, Jul 18, 2011 at 8:12 PM, Ishbir Singh <webmaster@ishbir.com>
> wrote:
> >>>
> >>> Hey,
> >>>
> >>> Fault is in-
> >>> posts = Post.query
> >>> Try replacing this with-
> >>> posts = Post.query.all()
> >>>
> >>> On 18 July 2011 16:02, Samrat Man Singh <samratmansingh@gmail.com>
> wrote:
> >>>>
> >>>> I've tried to write a very simple blog-engine-
> >>>>>>
> >>>>>> from flask import Flask, render_template
> >>>>>>
> >>>>>> import default_settings
> >>>>>>
> >>>>>> from flaskext.sqlalchemy import SQLAlchemy
> >>>>>>
> >>>>>> app = Flask(__name__)
> >>>>>>
> >>>>>> app.config.from_pyfile('default_settings.py')
> >>>>>>
> >>>>>> db = SQLAlchemy(app)
> >>>>>>
> >>>>>> class Post(db.Model):
> >>>>>>
> >>>>>>     id = db.Column(db.Integer, primary_key = True)
> >>>>>>
> >>>>>>     title = db.Column(db.String(255))
> >>>>>>
> >>>>>>     post_body = db.Column(db.Text)
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>     def __init__(self):
> >>>>>>
> >>>>>>         self.id = id
> >>>>>>
> >>>>>>         self.title = title
> >>>>>>
> >>>>>>         self.post_body = post_body
> >>>>>>
> >>>>>> def initdb():
> >>>>>>
> >>>>>>     db.create_all()
> >>>>>>
> >>>>>>     print "Initialized new empty database in %s" %
> >>>>>> app.config['SQLALCHEMY_DATABASE_URI']
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> '''class Admin(db.Model):
> >>>>>>
> >>>>>>     id = db.Column(db.Integer, primary_key = True)
> >>>>>>
> >>>>>>     username = db.Column(db.String(255))
> >>>>>>
> >>>>>>     password = db.Column(db.String(255))
> >>>>>>
> >>>>>> '''
> >>>>>>
> >>>>>> @app.route('/compose', methods = ['POST', 'GET'])
> >>>>>>
> >>>>>> def compose():
> >>>>>>
> >>>>>>     if request.method == 'GET':
> >>>>>>
> >>>>>>         return render_template('compose.html')
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>     title = request.form['title']
> >>>>>>
> >>>>>>     post_body = request.form['post_body']
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>     if request.form['action'] == 'Publish':
> >>>>>>
> >>>>>>         post = Post(title, body)
> >>>>>>
> >>>>>>         db.session.add(post)
> >>>>>>
> >>>>>>         db.session.commit()
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> @app.route('/')
> >>>>>>
> >>>>>> def index():
> >>>>>>
> >>>>>>     posts = Post.query
> >>>>>>
> >>>>>>     return render_template('posts.html', posts = posts)
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>> if __name__ == '__main__':
> >>>>>>
> >>>>>>     app.run()
> >>>>
> >>>> (I don't know where the problem really is so I've included the whole
> code
> >>>> here)
> >>>> The application runs but when I open it on the local server it shows
> the
> >>>> following error:
> >>>> SELECT post.id AS post_id, post.title AS post_title, post.post_body
> AS
> >>>> post_post_body FROM post
> >>>> I tried a few things like reinitializing the database, but that didn't
> >>>> really seem to help. Can someone help me with this please?
> >>>>
> >>>> Samrat
> >>>
> >>>
> >>> --
> >>> Regards,
> >>> Ishbir Singh
> >>
> >>
> >
>