views:

148

answers:

2

I am trying to develop a website for mobile and pc browser with django. and I am trying to figure out a best structure of the views and templates. there is what I have tried:

1) use different url ( like http://example.com/mobile/ and http://example.com/ OR http://example.com/?c=mobile ) to distinguish mobile and pc, and map them to different view which set different templates.

2) in the view set different template according to USER_CLIENT

3) use a wrapper layer of the view, the actual view just return the data to the wrapper, the wrapper set the different template.

Is there a common way to handle this in django? any suggestions and comments?

+1  A: 

Use Django's "sites" framework for a mobile version at http://m.example.com.

speakman
A: 

I would recommended solution 3; using a decorator to inspect the clients User Agent and returning à different template in case of a mobile agent.

Have the decorator take two arguments: the normal template, and the mobile template.

From your view, return a dict The decorator may pass to the rendering function as context. There is a decorator called 'render_to' that does this very well, Google for it.

To deal with the use case where users want the full version, even when browsing from a mobile device, you may use a redirecting view that sets a cookie your decorator may check for.

knutin