Sorry about this but i'm confused

Hey sorry about this but i'm terribly confused, i've been trying to get pythonanywhere working with for a while and i understand that it comes with a starter in but i have no idea how to link that with files from my dropbox folder or any other folder for that matter. Maybe i'm just being a massive noob but i really don't understand how this system works.

Hi bambo,

No need to be sorry! Maybe this will make it clearer. The example for that we include in the wsgi file is below.

import web
urls = ('/', 'index')

class index:
    def GET(self):
        web.header('Content-Type','text/html; charset=utf-8', unique=True)
        return """
                <title>Python Anywhere hosted web application</title>
            <h1>Hello, World!</h1>
                This is the default welcome page for a
                <a href="">PythonAnywhere</a>
                hosted web application.
                Find out more about how to configure your own web application
                by visiting the <a href="">web app setup</a> page

# comment out these two lines if you want to use another framework
app = web.application(urls, globals())
application = app.wsgifunc()

You could move all of that code into a file at "/home/bambo/".

Then inside the file you would just place these lines of code:

import os
import sys

path = "/home/bambo/"
if path not in sys.path:

from my_webapp import application

(EDIT - My bad, I had a trailing .py on the end of my_webapp, cut and paste error)

Does that make it clearer? The file just needs to contain an object called "application", that object needs to be a valid WSGI application. Where you import "application" doesn't matter. But you do need to be able to import it which is why we need to add the directory you are importing it from to your path.

Ahh! that make everything so much clearer!

Thanks a lot hansel.

well i did exactly as you said, and i get a 500 internal server error. Very strange

[Tue May 01 15:49:04 2012] Traceback (most recent call last): [Tue May 01 15:49:05 2012] File "/bin/", line 53, in main [Tue May 01 15:49:05 2012] application = get_application_with_error_logger(error_log) [Tue May 01 15:49:05 2012] File "/bin/", line 46, in get_application_with_error_logger [Tue May 01 15:49:05 2012] wsgi_module = imp.load_source('wsgi', '/var/www/') [Tue May 01 15:49:05 2012] File "/var/www/", line 8, in <module> [Tue May 01 15:49:05 2012] from code import application [Tue May 01 15:49:05 2012] ImportError: cannot import name application

i tried with "from import application" but that gave a different error about not finding the module.

Importing things always trips people up. My general piece of advice is to add some debugging code. You can use the call os.getcwd() and print sys.path to find out where your program is running and what the current path is set to.

In your specific instance I would first check the module "code" doesn't contain any syntax errors by running "python". Then I would check the code itself. The path is correct because the logs are telling you that. Maybe you haven't actually defined "application" inside the file?

try another file name rather than and it may work

As mopodo points out, your choice of filename is conflicting with Python's builtin code module. So, it finds that module earlier in the include path, but then fails because (not surprisingly) it doesn't define the name application to be imported.

I would strongly recommend renaming the file to something you can be sure is unique, such as - this should fix your issues.

If you're really attached to the name, however, you can probably make it work by subtly changing your file to this:

import os
import sys

path = "/home/bambo/"
if not sys.path or sys.path[0] != path:
    sys.path.insert(0, path)

from code import application

I should point out that with this approach any .py files you have in this directory will hide Python builtins or system libraries, which could create serious headaches for you. You have control over which libraries you import, but you may break libraries that they import which is a lot harder to figure out.

In short, just rename to something unique - it'll make your life a lot easier.

Thank you!

It was very useful for beginners


@faustinoaq: Welcome to PA! I hope you love it here!!