lundi 12 octobre 2015

How to import and save data from csv in web2py database table?

I used SQlite database. I wrote code like this

Module:
db.py
db = DAL('sqlite://storage.sqlite') 
db.define_table('data3')
db.data3.import_from_csv_file(open('mypath/test.csv'),'r')
Controller:
def website_list():
       return dict(websites = db().select(db.data4.ALL))
{{extend 'layout.html'}}
<h2>List Of Websites</h2>
<table class="flakes-table" style="width:100% ;">
        <thead>
                        <tr>
                          <td class="id" >ID</a></td>
                          <td class="link" >Link</td>
                        </tr>
        </thead>
        {{for web in websites:}}
        <tbody class="list">
            <tr>
                <td >{{=web.id}}</td>

                <td >{{=web.Link}</td>
            </tr>{{pass}}
        </tbody>
</table>

But it is showing error as

"type 'exceptions.AttributeError'"

Also error has this line Function argument list (self=, key='data3')

I think some thing is wrong in reading csv file. My csv file has following data

"Link_Title","Link"

"Apple's Ad Blockers Rile Publishers","somelink"

"Uber Valued at More Than $50 Billion","somelink"

"England to Roll Out Tailored Billboards","somelink"

Can anyone help in this..?

Aucun commentaire:

Enregistrer un commentaire