We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2fa11a8 commit caa88edCopy full SHA for caa88ed
test.py
@@ -0,0 +1,19 @@
1
+from django.conf.urls import url
2
+from django.db import connection
3
+
4
5
+def show_user(request, username):
6
+ with connection.cursor() as cursor:
7
+ # BAD -- Using string formatting
8
+ cursor.execute("SELECT * FROM users WHERE username = '%s'" % username)
9
+ user = cursor.fetchone()
10
11
+ # GOOD -- Using parameters
12
+ cursor.execute("SELECT * FROM users WHERE username = %s", username)
13
14
15
+ # BAD -- Manually quoting placeholder (%s)
16
+ cursor.execute("SELECT * FROM users WHERE username = '%s'", username)
17
18
19
+urlpatterns = [url(r'^users/(?P<username>[^/]+)$', show_user)]
0 commit comments