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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With