File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -102,15 +102,16 @@ The complete working example is provided below. And here are some general notes:
102
102
})
103
103
104
104
async def get_or_create (self ):
105
+ obj_id = self .get_argument(' id' , None )
105
106
async with self .application.objects.atomic():
106
107
obj, created = await self .application.objects.get_or_create(
107
- TestNameModel, id = 100 ,
108
- defaults = {' name' : " TestNameModel id=100 " })
108
+ TestNameModel, id = obj_id ,
109
+ defaults = {' name' : " TestNameModel id=%s " % obj_id })
109
110
return obj
110
111
111
112
app.add_handlers(' ' , [
112
113
(r " /" , RootHandler),
113
- (r " /create/ " , CreateHandler),
114
+ (r " /create" , CreateHandler),
114
115
])
115
116
116
117
# Setup verbose logging
@@ -123,8 +124,7 @@ The complete working example is provided below. And here are some general notes:
123
124
124
125
Try GET urls:
125
126
http://127.0.0.1:8888?id=1
126
- http://127.0.0.1:8888?id=2
127
- http://127.0.0.1:8888?id=3
127
+ http://127.0.0.1:8888/create?id=100
128
128
129
129
Try POST with name=<some text> data:
130
130
http://127.0.0.1:8888
Original file line number Diff line number Diff line change @@ -91,15 +91,16 @@ async def get(self):
91
91
})
92
92
93
93
async def get_or_create (self ):
94
+ obj_id = self .get_argument ('id' , None )
94
95
async with self .application .objects .atomic ():
95
96
obj , created = await self .application .objects .get_or_create (
96
- TestNameModel , id = 100 ,
97
- defaults = {'name' : "TestNameModel id=100" })
97
+ TestNameModel , id = obj_id ,
98
+ defaults = {'name' : "TestNameModel id=%s" % obj_id })
98
99
return obj
99
100
100
101
app .add_handlers ('' , [
101
102
(r"/" , RootHandler ),
102
- (r"/create/ " , CreateHandler ),
103
+ (r"/create" , CreateHandler ),
103
104
])
104
105
105
106
# Setup verbose logging
@@ -112,8 +113,7 @@ async def get_or_create(self):
112
113
113
114
Try GET urls:
114
115
http://127.0.0.1:8888?id=1
115
- http://127.0.0.1:8888?id=2
116
- http://127.0.0.1:8888?id=3
116
+ http://127.0.0.1:8888/create?id=100
117
117
118
118
Try POST with name=<some text> data:
119
119
http://127.0.0.1:8888
You can’t perform that action at this time.
0 commit comments