0

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))
View:
{{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..?

Kaggler
  • 21
  • 3
  • `db.define_table('data3')` Your table doesn't have any columns! Not sure about it! – Gaurav Vichare Oct 13 '15 at 06:29
  • You are importing data in table `data3`, but you are retrieving it from table `data4` – Gaurav Vichare Oct 13 '15 at 06:35
  • @Gaurav Thanks!!! I defined a table with fields and then tried to import data it works. – Kaggler Oct 13 '15 at 06:50
  • Also take `` outside for loop – Gaurav Vichare Oct 13 '15 at 07:19
  • As Gaurav suggests I added Fields and then Import csv. db.define_table('data7', Field('Title',requires =IS_NOT_EMPTY()), Field('Link',requires =IS_NOT_EMPTY())) db.data7.import_from_csv_file(open('mypath/test.csv'),'r') It works. But having new problem Each time I refresh my webpage It shows multiple records as below 1, Link1 2, Link2 3, Link1 4 Link2 I am getting repeated rows. Any solution ..? – Kaggler Oct 13 '15 at 10:12
  • You run the import on every view. See [this question](http://stackoverflow.com/questions/33118947/repetition-of-data-for-import-from-csv-file-in-web2py-for-sqlite-database-tabl) for more details – Remco Oct 16 '15 at 23:31

0 Answers0