def registercheck(request): email = request.GET.get('email') nickname = request.GET.get('nickName') checktype = request.GET.get('checkType') if int(checktype) == 0: record = getRecords(1, 1, 'myblog_user', '', ''.join(['and email = "', str(email), '"']), 'creatTime') else: record = getRecords(1, 1, 'myblog_user', '', ''.join(['and nickName = "', str(nickname), '"']), 'creatTime') name_dict = {'result': len(list(record))} return JsonResponse(name_dict)
def getUserModel(nickName): import sys reload(sys) sys.setdefaultencoding("utf-8") userModel = getRecords(1, 1, 'myblog_user', '', ''.join(['and nickName = "', str(nickName), '"']), 'id') ISOTIMEFORMAT = '%Y-%m-%d' u = userModel[0] u.creatTime = time.strftime(ISOTIMEFORMAT, userModel[0].creatTime.timetuple()) return u # def db(): # cursor = connection.cursor() # 获得一个游标(cursor)对象 # # 更新操作 # cursor.execute('update other_other2 set name ="李四" where id=%s', [3]) # 执行sql语句 # transaction.commit_unless_managed() # 提交到数据库 # # 查询操作 # cursor.execute('select * from other_other2 where id>%s', [1]) # raw = cursor.fetchone() # 返回结果行 或使用 #raw = cursor.fetchall() # # # 如果连接多个数据库则使用django.db.connections # from django.db import connections # _cursor = connections['other_database'].cursor() # # 如果执行了更新、删除等操作 # transaction.commit_unless_managed(using='other_databases')
def blogedit(request): content = {} theid = request.GET.get('id') if theid is not None: record = getRecords(1, 1, 'myblog_blog', '', ''.join(['and id = ', theid]), 'timestamp') content['record'] = record[0] return render(request, 'blog/blogEdit.html', {'content': content})
def blogdetail(request): content = {} theid = request.GET.get('id') record = getRecords(1, 1, 'myblog_blog', '', ''.join(['and id = ', theid]), 'timestamp') content['record'] = record[0] content['userModel'] = getUserModel(request.user.username) return render(request, 'blog/blogDetail.html', {'content': content})
def saveblog(request): blogcontent = request.POST['content'] userid = request.user.id title = request.POST['title'] blog.authorid = userid blog.content = blogcontent blog.title = title fmt = '%Y-%m-%d %X' blog.timestamp = time.strftime(fmt, time.localtime()) blog.view = 0 theid = insert(blog) content = {} record = getRecords(1, 1, 'myblog_blog', '', ''.join(['and id = ', str(theid)]), 'timestamp') content['record'] = record[0] return render(request, 'blog/blogDetail.html', {'content': content})