Forums

help understand file addressing

Hello there,

I am just getting to know with all these stuff, and need some help. I have the file asfasf_pythonanywhere_com_wsgi.py. I would have expected it to be index.py or whatsoever. I can't understand why is it the equvialent of index.html whatsoever. Another question is how to add more python code to build other parts of my website. I mean something like a contact.py to generate contact.html. Could you please tell me what does urls=(... does in the following snippet, and how to solve the above issues.

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

class index:
     def GET(self):
        web.header('Content-Type','text/html; charset=utf-8', unique=True)

Sorry for my bad English!

Thank you very much indeed,

Well,

asfasf_pythonanywhere_com_wsgi.py is not in anyway equivalent to index.html. Instead it is a Python application that accepts HTTP requests, and sends http responses.

Each HTTP request includes a URL. If the URL is "/" then the Python application uses the GET method of the index class.

If the HTTP request had a URL that was "/contact" then made you could map it to the contact class. Like this

urls = (
    "/", "index",
    "/contact", "contact",
)

 class index:
 def GET(self):
    web.header('Content-Type','text/html; charset=utf-8', unique=True)

 class contact:
 def GET(self):
    return "<html><body><p>Some contact details</p></body></html>"

Does that make sense? Of course you don't need to write your html entirely by hand. You would use a template to generate it. But I'm just trying to show you the relation between a class with a GET method that returns some html and the older, static file way of just serving a contact.html file straight from the file system.

Read more about web.py's url handling here

Thanks a lot, I tried it but it returns "not found" when I try to load asfasf.pythoneverywhere.com/contact I wonder what went wrong now?

What did you actually try and change? The file you will need to add the URL and contact class to would be

/var/www/matekovacsdeak_pythonanywhere_com_wsgi.py