npm install -g weapp-cookie
新建一个lib目录
复制weapp-cookie到lib目录
在app.js写入
import 'lib/weapp-cookie/index'
后端代码
class PostDetailView(MysqlView):
async def get(self, post_id, *args, **kwargs):
post = await self.objects.get(Posts, id=int(post_id))
if not self.get_cookie("view_num"+post_id):
post.view_num += 1
await self.objects.update(post)
self.set_cookie("view_num"+post_id, "yes")
data = model_to_dict(post)
self.finish(json.dumps(data, default=json_serailize))
网友评论