The FuqIt Web Framework
I'm kind of tired of following the stupid rules of MVC and want to just try out making something where I shit files into a directory and they just work. This Python web framework (if you can call it that) is my first crack at something like that. I basically did this on a Saturday morning because I was bored. If you don't like it, then oh well, life goes on.
How It Works
- fuqit init -into test
- ./bin/fuqit run -chroot test
- Browser http://localhost:8000/
That's it. Look in this project's test/app/ directory to see me doing stupid crap with it to see if it works.
Easy, and designed to treat raw .html Jinja2 templates the same as a .py file module:
- If it's in /static/ it's a static file.
- If it has an extension it's a template.
- If it ends in / it's either /index.html or a module.
- Otherwise it's a module named after the path with / changed to . unless there is a directory with the same path, then this will produce a redirect.
- Modules are found by trying to import longest to shortest paths.
- / -> /index.html or /index.py
- /the/stupid/place/stuff.txt -> jinja template same path
- /the/other/place/index.html -> same thing
- /mystuff/cool -> a module named app.mystuff.cool
- /dir/that/exists -> redirect to /dir/that/exists/
- /mymodule/the/path/after/that -> import mymodule.py give it sub_path=/the/path/after/that
It uses the python mimetypes module to figure out mimetypes by extension. No, I don't know how to add new extensions to it.
It has ephemeral sessions based on cookies, which means that they go away when you reboot the process. To use sessions you can either use them raw from fuqit/sessions.py or just do this:
from fuqit.sessions import with_session @with_session def GET(variables, session): session['count'] = session.get('count', 1) + 1 return "COUNT: %d" % session['count']
You can play with the example by doing this::
./bin/fuqit run -chroot examples/test -app app
Then go to http://127.0.0.1:8000/ and you'll get my little demo testing app. It's in the app directory and just has some files for testing the rendering.
You can get help for run with:
./bin/fuqit help -for run
Writing A .html Handler
Here's how you do it:
- Make a .html file in the app directory.
- Put jinja2 syntax stuff in it.
- You get a web variable to play with that has all the gear, including sessions, headers, response_headers, and a module function for easily loading code.
- Hit it with a browser. That's it.
Writing A Module Handler
Here's how you do it:
- Make a .py file with the name you want.
- Put either a run, GET, or POST method in it. run handles every possible request, GET or POST handles just those.
- Your method will get one parameter, web, which has .session, .headers, .app, and everything.
- Return a string for the body; a body, code, headers tuple; or just call web.app.render("somefuqitpath.html", web)
Remember that if you have say /myapp.py and you get a URL of /myapp/stuff/things, then this module will run and it'll get a web.sub_path == '/stuff/things'.
Here's how you do it:
- mkdir app/static
- Put the static crap in there.
- Any URL with /static/ in front serves out of there.
If you actually host it you should have your fronting web server serve them straight out of there.
FuqIt took the public domain web.py database module and uses that. The best docs for it is currently from the Web.py folks over at http://webpy.org/docs/0.3/tutorial#databasing.
You use a database by doing two things:
- Edit the config.py file that fuqit makes for you. Inside there is an initial configuration that makes a db variable configured from the fuqit.data.database call.
- Change the data.database call to use the database you want. It's currently setup to use a SQLite3 database.
That's it. Once you have that configure, the web variable in templates and modules will have a web.db variable for you to do database stuff with.
Web.py Database Modifications
There are a few minor modifications to the default web.py that you need to know:
- It's renamed data so that it can be more than just for databases and so it doesn't conflict with the db variable in config.py.
- I added a web.db.get() function that's a reduced version of web.db.select() that is used to just get one record.
As I evolve web.py's DB I'll just call it the fuqit.data API and document it differently.
But That's Magic!
I will refer you to our official Mascot:
Do you have a load of money and are you looking for the next Meteor to waste it on? Well this project is currently looking for funding and it's already been on the top of HackerNews!
Act fast because pretty soon I'll have a spare Sunday and FuqIt will become more secure than both Meteor and Ruby On Rails and then you'll miss out on investing in the next hottest thing. You'll have to go buy some Gucci hand bags or a DVF dress to be in-fashion instead. Can't have that now.