I typically check the content type and have the response match the content
type of the incoming request.  I also typically have this be the only
decision that lives within views.py, and in turn calls out to code in other
modules to handle xml and/or html presentation respectively.  Also, I would
recommend using an xml processing/generating library.

Brian

On Tue, Sep 21, 2010 at 1:39 AM, Brendon <brendon.j.co...@gmail.com> wrote:

> Hi all,
>
> I want to use DJango to implement an XML based RESTful API and a
> website together using DJango. I am wondering if anyone here is aware
> of any tutorials on ways of achieving this in DJango without
> duplicating too much code?
>
>
> Basically what I want to achieve is to use the same core logic for
> both the website and the API and just have different presentation
> layers for the two systems. I have not seen any tutorials or the like
> on doing this sort of thing and was wondering if people here have
> suggestions on best approaches or tutorials that might show good ways
> to structure this.
>
> The idea is that all interaction using the API uses XML. The POST data
> sent to the server and responses from the server are all using an XML
> schema that we have designed for our application. All interaction with
> the website is the same but uses normal web forms etc for the
> interface of the presentation layer.
>
> Example API:
> * GET   : https://mywebsite/api/rooms/ : List available rooms, returns
> XML with a list of Room ID's
> * POST : https://mywebsite/api/room/  : Create a new room, raw POST
> data is XML with the parameters required to create a room, on success
> returns a Room ID
> * GET   : https://mywebsite/api/room/<room-id>/ : Retrieves details
> about an existing room
> * POST : https://mywebsite/api/room/<room-id>/ : Modifies details for
> an existing room
> * DELETE : https://mywebsite/api/room/<room-id>/ : Delete a room
>
> Now, on the website side of things I want to do exactly the same but
> as part of a a nice HTML site (with menus for navigation, nice graphs
> to display relevant data etc).
>
> Example Web:
> * GET   : https://mywebsite/web/rooms/ : Displays a page with a list
> of links to available Rooms.
> * GET   : https://mywebsite/web/room/   : Displays a page with a form
> requesting input of all necessary data to create a new room.
> * POST : https://mywebsite/web/room/   : Create a new room. POST data
> comes from form displayed previously (on error redisplays form). On
> success redirects the user to the details page for that room.
> * GET   : https://mywebsite/web/room/<room-id>/ : Displays details
> about an existing room and provides it in a form that can be used to
> change the data with a POST
> * POST : https://mywebsite/web/room/<room-id>/ : Modifies details for
> an existing room
> * DELETE : https://mywebsite/web/room/<room-id>/ : Delete a room
>
>
> Thanks,
> Brendon.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Brian Bouterse
ITng Services

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to