4 ms·
Instead of creating a cookie manually, you can save 4 lines and use the .set_cookie()[1] method on the response object. Also, take a look at the render()[2] sh
by paulsmith 15y ago
Instead of creating a cookie manually, you can save 4 lines and use the .set_cookie()[1] method on the response object.
Also, take a look at the render()[2] shortcut function to collapse the template loading, context settings, and rendering steps into one.
[1]: https://docs.djangoproject.com/en/1.3/ref/request-response/#django.http.HttpResponse.set_cookie https://docs.djangoproject.com/en/1.3/ref/request-response/#...
[2]: https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/#render https://docs.djangoproject.com/en/1.3/topics/http/shortcuts/...
- theroo 15y agoAlso, setting the cookie 'todos' to todolist.id will allow anyone to manipulate the value of that cookie in order to read anyone's cookies.
- po 15y agoWith Django 1.4 (or the dev version) it will be possible to cryptographically sign a cookie: https://docs.djangoproject.com/en/dev/topics/signing/ https://docs.djangoproject.com/en/dev/topics/signing/ You can use this to store the session data with the user without having to consult a database and without fear that they will tamper with the id: https://github.com/ericflo/django-cookie-sessions https://github.com/ericflo/django-cookie-sessions
- chernevik 15y agoFurther line saving: The << methods >> dictionary isn't needed, it's just mapping lower case strings to upper. Replace: return methods[request.method](request, item_id) with: return request.method.lower(request, item_id)