Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Updated the tutorial... #23

Merged
merged 1 commit into from

2 participants

@CoolGoose

...for some reason in Ubuntu 12.04 with python 2.7.3 the web.application call had to be in the main call (if not it gave a AttributeError: 'builtin_function_or_method' object has no attribute 'iteritems') and it's showing now the code for the first part of the tutorial for easier access.

@CoolGoose CoolGoose Updated the tutorial, for some reason in Ubuntu 12.04 with python 2.7…
….3 the web.application call had to be in the main call (if not it gave a AttributeError: 'builtin_function_or_method' object has no attribute 'iteritems') and it's showing now the code for the first part of the tutorial for easier access.
c14f4f1
@aaronsw aaronsw merged commit 1038fae into webpy:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 14, 2012
  1. @CoolGoose

    Updated the tutorial, for some reason in Ubuntu 12.04 with python 2.7…

    CoolGoose authored
    ….3 the web.application call had to be in the main call (if not it gave a AttributeError: 'builtin_function_or_method' object has no attribute 'iteritems') and it's showing now the code for the first part of the tutorial for easier access.
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 9 deletions.
  1. +22 −9 docs/0.3/tutorial.md
View
31 docs/0.3/tutorial.md
@@ -44,12 +44,6 @@ The first part is a [regular expressions](http://osteele.com/tools/rework/) that
This line says we want the URL `/` (i.e. the front page) to be handled by the class named `index`.
-Now we need to create an application specifying the urls.
-
- app = web.application(urls, globals())
-
-This tells web.py to create an application with the URLs we listed above, looking up the classes in the global namespace of this file.
-
<a name="getpost"> </a>
## GET and POST: the difference
@@ -65,14 +59,33 @@ In our web.py code, we make the distinction between the two clear:
This `GET` function will now get called by web.py anytime someone makes a `GET` request for `/`.
-Alright, now we just need to finish up with a final line telling web.py to start serving web pages:
+Now we need to create an application specifying the urls and a way to tell web.py to start serving web pages:
- if __name__ == "__main__": app.run()
+ if __name__ == "__main__":
+ app = web.application(urls, globals())
+ app.run()
-This tells web.py to serve the application we created above.
+First we tell web.py to create an application with the URLs we listed above, looking up the classes in the global namespace of this file.
+And finally we make sure that web.py serves the application we created above.
Now notice that although I've been talking a lot here, we only really have five or so lines of code. That's all you need to make a complete web.py application.
+For easier access, here's how your code should look like:
+
+ import web
+
+ urls = (
+ '/', 'index'
+ )
+
+ class index:
+ def GET(self):
+ return "Hello, world!"
+
+ if __name__ == "__main__":
+ app = web.application(urls, globals())
+ app.run()
+
<a name="start"> </a>
## Start the server
Something went wrong with that request. Please try again.