Forums

how to upload a existing database and how to use it?

Hi everyone, its my first time to use pythonanywhere,i have a finished project with bottle+sqlite3. I have no idea how to do with my database. I have uploaded it into my files under mysite,and if i want to connect the database

con = sqlite3.connect('imdb.db')
cur = con.cursor()
cur.execute("SELECT FilmID FROM Filmbilder")

the error: Error no such table: Filmbilder: Traceback (most recent call last):
File "/home/jiaxiang/mysite/my.py", line 64, in <module>
sys.exit(1)
SystemExit: 1

thanks for your answer!

Would you mind if I took a quick look at your files to try to debug this?

Thats no problem how can u take a quick look at my files?

OK, in your home directory there is a file called imdb.db, but it's zero bytes in length. Perhaps something went wrong when you uploaded it?

thx for ur answer!But i saw the date imdb.db is 1.2MB,is something wrong?

Could you tell me where it says that? I'm looking on our file server in your sandbox, and it says it's 0 bytes there.

under mysite there is a list I have copied it.

New Filmbeschreibung.py 301 bytes FilmbilderInsert.py 295 bytes bewertung.py 220 bytes bottle.py 131.4 KB bottle.pyc 147.2 KB eingeloggt.tpl 2.0 KB film_information.tpl 4.6 KB film_informationWithComment.tpl 2.9 KB imdb.db 1.2 MB lieblingsfilme.tpl 258 bytes login.tpl 247 bytes make_table.tpl 1.6 KB my.py 22.3 KB profil.tpl 2.1 KB register.tpl 724 bytes

If u r administrator,u must my username and password,you might log in and have a look. Thx!

Hi jiaxiang,

Yes Giles and I are both administrators. You can tell by the little python icons next to our names. You should try providing the full path to your database. Which in your case would be /home/jiaxiang/mysite/imdb.db.

thx for your help!I can connect fine with my database. But i have still a little problem with picture.My program loaded the pictures from database into local disk,why i cant play the picture under <td><img border="0" src={{"/home/jiaxiang/mysite/1.jpg"}} alt="picture is not vorhanden" width="294" height="453"></td> I have tried different ways.I want to know except using static file is there any other possiblities? best regards Jiaxiang

To serve images you need to use one of two basic approaches:

  • Static file support, by placing the file in subdirectory listed as static on your web tab.
  • By implementing a hook in your WSGI application which handles a request by opening the image file and serving the contents as the response data.

The second method is the only way to get the file to be served without using the static file support, but it's a bit more fiddly. You need to make sure you serve only the image content and not accidentally include any templating (such as HTML tags), and you also need to set the Content-Type header correctly - for a JPEG, for example, it would be image/jpeg.

Yeah, I would just use the built in static file support.

Put all your images in a folder called `/home/jiaxiang/mysite/static'

Make a static mapping on the web apps tab with URL = "/static/", and PATH = "/home/jiaxiang/mysite/static".

Then in your webpage you can refer to an image like this <img border="0" src="/static/1.jpg" alt="picture is not vorhanden" width="294" height="453">

thx for your answer! Its very helpful!

I think I'm gonna learn German yet!