1

I'm working on an application where you can browse folders and files in a treemap view. Since I'm working with a lot of data I don't want to load all of the JSON data at once, instead I display all files for a particular folder when the folder is clicked.

As it is now, I take the folder id and include it in the url, like so www.mysite.org/1 which is mapped in Django's urlconf to a particular view serving file json for that folder id.

What is the best way to go, when should I pattern match with the urlconf, and when should I use GET/POST?

danihodovic
  • 1,151
  • 3
  • 18
  • 28

2 Answers2

2

The way you're doing it now seems fine since you have a single numeric ID for each folder. If you wanted to pass a lot of parameters at once, especially if the set of parameters is not always the same, GET params are more appropriate.

POST is not relevant here as it is meant for updating data on the server, rather than simply requesting existing data.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • In reality I'm using 3 different parameters served by 3 views (it's much cleaner this way, I've tried using 1 view). Is the urlconf still a better option? All of the parameters are numerical. – danihodovic Jul 16 '14 at 08:15
  • Well this has become a bit too abstract to answer, really. It's up to you, especially as the URLs are not publicly visible anyway. – Daniel Roseman Jul 16 '14 at 08:24
  • So there is not best practice when using integer id's and not passing around too many parameters? The urlconf solution is just as good as the GET? – danihodovic Jul 16 '14 at 08:35
0

I would recommend setting up an API (Tastypie or Django Rest Framework)

You could create something like this /api/v1/YOUR_APP_NAME/?limit=20 (Tastypie default has a limit of 20 per request)

Now you don't have to have a separate url in Django for it and you have created a nice api and unless you want to insert data you should always use a GET request.

Eagllus
  • 437
  • 3
  • 8