def index(request): logging.debug(request.headers.cookies) cookie = request.headers.cookies(COOKIE_NAME) logging.debug(cookie) if cookie: vars = cookie.split('-') print(vars) else: logging.debug("no cookie") summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' blogs = [ Blog(id='1', name='Test Blog', summary=summary, created_at=time.time() - 120), Blog(id='2', name='Something New', summary=summary, created_at=time.time() - 3600), Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time() - 7200) ] return {'__template__': 'blogs.html', 'blogs': blogs}
async def index(request): summary = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.' blogs = [ Blog(id='1', name='Test Blog', summary=summary, created_at=time.time() - 120), Blog(id='2', name='Something New', summary=summary, created_at=time.time() - 3600), Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time() - 7200) ] return { '__template__': 'blogs.html', 'blogs': blogs }
async def index(request): summary = '郭浩伟爱着程锡慧,他将会为了他们的家庭努力,好好工作,好好生活。' blogs = [ Blog(id='1', name='Test Blog', summary=summary, created_at=time.time() - 120), Blog(id='2', name='Something New', summary=summary, created_at=time.time() - 3600), Blog(id='3', name='Learn Swift', summary=summary, created_at=time.time() - 7200) ] return { '__template__': 'blogs.html', 'blogs': blogs }
def index(request): summary = 'abc' blogs = [ Blog(id='1', name='Test Blog', summary=summary, created_at=time.time() - 120), Blog(id='2', name='Something New', summary=summary, created_at=time.time() - 3600), Blog(id='3', name='Python', summary=summary, created_at=time.time() - 4800) ] return { '__template__': 'blogs.html', 'blogs': blogs }
def index(request): summary = "The summary of the Project. liguangyu's Demo" blogs = [ Blog(id=1, name='Test Blog', summary=summary, created_at=time.time() - 120), Blog(id=2, name='Something New', summary=summary, created_at=time.time() - 3600), Blog(id=3, name='Learn Swift', summary=summary, created_at=time.time() - 72000) ] return {'__template__': 'blogs.html', 'blogs': blogs}
def post_blog(request): dic = request.form if 'id' in dic: Blog.delete(dic['id']) dic['name'] = request.cookie['name'].value blog = Blog(**dic) blog.insert() request.status = '303 See Other' request.header.append(('Location', '/hello/' + blog.id)) return request
async def api_create_blog(request, *, name, summary, content): check_admin(request) if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty.') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) await blog.save() return blog
async def index(request): ''' 用户浏览页:首页 ''' summary = 'Lorem ipsum dolor sit amet, consectetur adpipislicin elit sed wo tempo inciditundng up labore et doloire mabndf aliquea' blogs = [ Blog(id='1', name='Test Blog', summary=summary, create_at=time.time() - 120), Blog(id='2', name='Something New', summary=summary, create_at=time.time() - 3600), Blog(id='3', name='Learn Swift', summary=summary, create_at=time.time() - 7200) ] return {'__template__': 'blogs.html', 'blogs': blogs}
def api_create_blog(request, *, name, summary, content): # @copy_current_request_context # def do_some_work(): check_admin(request) if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty.') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) yield from blog.save() return blog
def apiCreateBlog(request, *, name, summary, content): checkAdmin(request) if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty') blog = Blog(userId=request.__user__.id, userName=request.__user__.name, userImage=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) yield from blog.save() return blog
async def api_create_blog(request, *, name, summary, content): check_admin(request) if not name or not name.strip(): raise APIValueError('name', 'name cannot be empty') if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty') if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty') blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) await blog.save() logging.info('blog %s' % (json.dumps(blog).encode('utf-8'))) return blog
def api_create_blog(request, *, name, summary, content): #校验当前用户权限: check_admin(request) #校验传递值中参数‘name’是否为空或空串,为空则抛出异常: if not name or not name.strip(): #参数‘name’为空则抛出异常: raise APIValueError('name', 'name cannot be empty.') #校验传递值中参数‘summary’是否为空或空串,为空则抛出异常: if not summary or not summary.strip(): raise APIValueError('summary', 'summary cannot be empty.') #校验传递值中参数‘content’是否为空或空串,为空则抛出异常: if not content or not content.strip(): raise APIValueError('content', 'content cannot be empty.') #创建Blog实例: blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) #将Blog信息存储到数据库: yield from blog.save() return blog
async def createBlog(request, *, name, summary, content, id): #check_admin(request) if 0 == id: blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip()) await blog.save() else: blog = await Blog.find(id) if blog: blog.update({ 'name': name, 'summary': summary, 'content': content }) await blog.save() else: return Exception('No blog found') return blog