I've been looking into Django more. I was wondering the best way to automatically return the correct response format for any given type of request. Specifically, I'm interested in distinguishing between html and json requests.

In the past I've just appended '/json' to a given url to get json data, but then I was curious how Rails seems to automatically know what the request format was. According to this:


"Rails determines the desired response format from the HTTP Accept header submitted by the client."

It looks like there is similar functionality in Django, but the routing is not as built in as in Rails.


You can use request.is_ajax(). But that requires that the HTTP_X_REQUESTED_WITH header is set. Most JavaScript libraries do this automatically, but if you're using some other type of client, you'll need to make sure it sets it as well. Alternatively, you can pass a querystring such as ?json with the URL and then check request.GET.has_key('json'), which is probably a little more foolproof.

More details are available here:

I usually don't remember the syntax for HTML forms. Inevitably, when I'm starting a project, I need to go look up the basics. Then, I usually reuse the template that I come up with and don't look back. Here are some notes on those basics...

There is a python module, webhelpers, that will help in generating form markup:

This also turns out to be a good reference for common html tags, even if you don't want to generate them:

center page content
This will only work if the DOCTYPE is XHTML Transitional or Strict. IT WILL NOT WORK if your doctype is HTML 4.x. Here is an example of what it should look like:

Put this at the top of your CSS file and you will be good to go!
#html, body {
top: 0px;
right: 0px;
bottom: 0px;
left: 0px;
height: 100%;
margin: auto;

there seem to be many approaches these days for blocks with rounded corners.

there was one fully CSS version that draws one line rows along the top and bottom of the block with margins to give the rounded effect:

The rest use 2-4 images to get the effect

rounded corners css - Google Search
25 Rounded Corners Techniques with CSS
Spiffy Corners - Purely CSS Rounded Corners

Deliverance does transformations of HTML to 'theme' pages, similar in function to XSLT but using a simpler XML-based language to express the transformation.

Deliverance Introduction - deliverance - OpenPlans
Specification for Deliverance - deliverance - OpenPlans