views:

115

answers:

1

I'm converting a small PHP application to Django.

One section has a long query string, indicating how a widget is to be displayed. There are a few required parameters and several optional ones.

The current urls read like:

app.php?id=102030&size=large&auto=0&bw=1&extra=1

The id and size are required, but auto, bw and extra are optional. I use defaults if they're not specified.

My first idea was to make a django URL pattern with the required info, id and size:

url(r'^/app/(P?<id>)\d+/(P?<size>)\w+$',app.project.views.widget,name='swidget')

The optional parameters would then be a query string, like

/app/102030/large?auto=0&bw=1&extra=0

Is it a common practice to mix GET parameters with parameters defined in the URL conf in Django? Or should I make it like

url(r'^/app/(P?<id>)\d+/(P?<size>)\w+/(P?<auto>)\d/(P?<bw>)\d/(P?<extra>)\d[/]?,'app.project.views.widget,name='swidget')
#so it would look like:
/app/102030/large/0/1/0/

Any suggestions about best practices or issues to keep in mind with either style are appreciated!

+7  A: 

If you consider that "URL" stands for Uniform Resource Locator, the URL should only indicate the resource being displayed, and any 'configuration' options should be passed as parameters. So, I think your first idea is fine.

harto
That's a good insight. So, the parameters that would represent a truly different resource if changed should be in the URL definition, and the minor ones (autoplay or not, etc) can be GET params.
Alex JL
I think so. Particularly if those minor parameters are optional, or can have meaningful default values.
harto