My old do-it-yourself framework tutorial was getting a bit long in the tooth, so I rewrote it to use WebOb. Now: the new do-it-yourself framework.
Automatically generated list of related posts:
- The Shrinking Python Web Framework World When I was writing the summary of differences between WebOb...
- JSON-RPC WebOb Example I just saw this json-rpc recipe go by as a...
- WebOb I’ve have it in my head to extract/rewrite parts of...
- WebOb decorator Lately I’ve been writing a few applications (e.g., PickyWiki and...
- What Does A WebOb App Look Like? Lately I’ve been writing code using WebOb and just a...
“The return value of __ import __ isn’t very useful”
What’s wrong with module returned by __ import __()?
Maybe you could add in the introduction some links on how to obtain and install WSGI and WebOb?
This is the kind of stuff I’ve been looking for to fill my pythonic gap after learning the basics and before banging my head on the wall with anything too big =)
Hey Ian,
I’ve been playing with webob a lot lately and I gotta say that it’s great! In all my past apps, I’ve been trying to model requests/responses in a nice Pythonic and RESTful way but never quite made it, so webob is just what I’ve been looking for.
I was wondering if there was any plans on letting webob Request objects make actual HTTP calls, returning webob Responses? I wrote a wrapper class to do it, but I think it’d make sense to be part of the Request object. If it’s something you’d be open to, I’d like to contribute some code.
.Carlo
Niki:
__import__
returns the first segment of whatever you import. So if you do__import__('mypackage.mymodule')
it returnsmypackage
. Just getting the module fromsys.modules
is, I’ve found, the easiest way of getting at the module that was actually imported.Carlo: yes, you can do that. To do it you need to pass a proxy application to
req.get_response()
. There’s one in [WSGIProxy](http://pythonpaste.org/wsgiproxy/), inwsgiproxy.exactproxy.proxy_exact_request
. So you can do:proxy_exact_request
is named as such because it has no options, but reads the exact information the request contains (including stuff like SERVER_NAME so you can send a request not by DNS).Ian & Niki:
For
__import__
, you can also give the 4th argument as a list with a single empty string. This is the “context” argument, meaning it acts likefrom x import y
, context being the x bit. Giving it an empty string makes it return the last bit of the first argument.For example:
returns module, not some.
Sorry for double posting. This is actually what I came to post.
I’m not sure wether you’ve read Diving into Python. The way code is commented in that book is absolutely genius. You see a big piece of code, just like yours. And below it you find a numbered explanation of every relevant line or group of lines.
I’m saying this because I had my little problems understanding what exactly your code does. Like the routing templating thing. I thought “Okay. This turns our nice routing syntax into actual regular expressions to use elsewhere. But how does he do it?”.
I agree that writing a framework is a useful exercise, and think that a language should provide the one true framework as a mis-notion for people that want an out of the box solution to a complex problem.
I’ve found webob both very useful and fun to use in writing simple RESTful apps. I’ve written a paster template for a simple view with webob that might be useful to some, at least for reference: https://svn.openplans.org/svn/standalone/webob_view/trunk/ This could be used or be modified to be used with a simple framework/routing system as presented in the tutorial — just have a bunch of views with a route for each == website.
Hi Ian. Once again you wrote a great article where each line is full of new things to learn. Inspired by this I wrote a little Python framework that supports GAE and Paster. It uses your appengine_monkey patches which I updated on some places to make some bug fixes, mainly for Windows. If you find the time to have a look at it and tell me what you thing about it I would be very glad. Here is the project page:
http://code.google.com/p/pyxer/
Thanks again for the very cool and useful tools you wrote. Dirk