Forums

How to configure an Bottle app on pythonanywhere?

Grettings.

I'm new on pythonanywhere, i'm trying to setup an Bottle app but allways get an Error 500, coud you please explain me the right way to get it work?

Thanks in advance.

Hi,

I see that the site at pegazux.pythonanywhere.com is working. Is that the bottle installation? If it is can you let us know what the problem was so we can help other users that want to use bottle?

Thanks

Hi,

yes, I finally got it work changind the WSGI file in this way:

=====================================

import bottle
from bottle import route

t_test = main.main.test()

@route('/')
def hello():
    return "Hello pythonanywhere with bottle!"


application = bottle.default_app()

=====================================

But now i'm stuck trying to import a module from my "home/pegazux" folder, if I write "Import main", an Error 500 is returned, and in the Error Log apears that module main doesn't exist, "home/pegazux" and "home/pegazux/main" folders are added to the PYTHONPATH by editing pythonstartup.py, that now it looks like:

=====================================

import rlcompleter
import readline
import sys

sys.path.append ("/home/pegazux")
sys.path.append ("/home/pegazux/main")

readline.parse_and_bind("tab: complete")

=====================================

And "home/pegazux/main" contains the files:

init.py main.py

The "init.py" file contains this code:

=====================================

import main as main

=====================================

And "main.py" contains:

=====================================

class test:
    def __init__(self):
        self.Nombre = "Henry"

=====================================

And if I change the WSGI begining code for this:

=====================================

import bottle
from bottle import route
import main # -<--- Note this is the unique one change!!

t_test = main.main.test()

@route('/')
def hello():
    return "Hello pythonanywhere with bottle!"


application = bottle.default_app()

=====================================

Then the Error 500 appear. I and future users will be apreciate your help whit this,

Thanks in advance.

The pythonstartup file is only executed when Python is started in interactive mode. You also need to put those sys.path.appends into your wsgi file before you try to import main. I also think that the call to main.main.test() may be incorrect for your setup. It's more likely to be main.test(). I'm also not sure what you're trying to achieve with init.py -- I'm not sure it makes sense to do that. What are you trying to do there?

[RESOLVED]

Thanks glenn for your advice, I've changed my code and orientation and it's done and running ok.

this is the correct wsgi.pi code:

import sys
import bottle

sys.path.append ("/home/Pegazux")

from main_app import app

application = bottle.default_app()

And now in the proyect folder in my case "/home/Pegazux" create a new python package (new folder) named "main_app", in it we're going to create or add a new file called "app.py" with a simple code that just returns an string like this:

from bottle import route

@route('/')
def hello():
    return "Hello pythonanywhere with bottle!"

Now it's very important that in order python recognize this folder and its content as a package we need to include a file in it called __init__.py and inside this declare the module that are going to being called from wsgi.pi, the code is next:

import app as app

And that's it, we are ready to go, just save any changes, reload the web app and enjoy PA + Bottle.

thanks to the staff support, that helped me to clear my mind and to figure it out how to complete this task.

Just thought I would add for anyone else reading this that Pegazux is talking about a file called

__init__.py

The markdown is eating his double underscores.

Cheers

Thanks buddy, a question there's any way to edit my post, in order to correct it and can be view it as code.

Thanks

As it happens, Hansel and I were just working on the "edit own posts" feature today. Should be released soon...

That's a good new, by the way I offer my self to help in case if you're needing of coder force.

Okay, we'll we finished the edit own posts feature. Not sure exactly when we will deploy it to live but hopefully Monday?

Thanks for the offer of CODER FORCE!!

Cheers

Hansel

hi

How do I add websocket to Bottle so that its launch does not hang forever and I do not have to reinstall it.

Unfortunately we don't support websockets in PythonAnywhere websites right now.

;'-{{{{{{{{{{{{{{{{{ When will you add the websockets?

It's on our list of things to do, and we are building out infrastructure and working our way towards eventually supporting it. Thanks for your patience in the mean timeeeeeeee.