def test_reptile(request): target = 'http://www.biqukan.com/1_1094/5403177.html' req = requests.get(url=target) html = req.text bf = BeautifulSoup(html) texts = bf.find_all('div', class_='showtxt') print(texts[0].text.replace('\xa0' * 8, '\n\n')) return return_success("")
def login(request): if request.POST: userName = request.POST['userName'] passWord = request.POST['passWord'] # book = User.objects.get(password=passWord, name=userName) try: book = User.objects.get(password=passWord, name=userName) except: return return_failure(code=2001, msg="验证码或密码不正确") return return_success(object_to_json(book))
def get_news(request): page = 0 try: page = request.POST['page'] except Exception as e: print(e) try: joke_list = News.objects.all().values()[int(page) * 10:int(page) * 10 + 10] return return_success(list(joke_list)) except: return return_failure(code=2004, msg="没有更多数据")
def get_joke(request): page = 0 try: page = request.POST['page'] except Exception as e: print(e) try: joke_list = Joke.objects.filter(~Q( url='')).all().values()[int(page) * 10:int(page) * 10 + 10] # joke_list = Joke.objects.all().values()[int(page)*10:int(page)*10+10] return return_success(list(joke_list)) except: return return_failure(code=2004, msg="没有更多数据")
def registered(request): if request.POST: userName = request.POST['userName'] passWord = request.POST['passWord'] # 判断用户名 try: user = User.objects.get(name=userName) except Exception as e: user = None if user: return return_failure(code=2002, msg="当前用户已存在") # if any(book): # return return_failure(code=2002, msg="当前用户已存在") # except: test1 = User(name=userName, password=passWord) test1.save() book = User.objects.get(pk=test1.pk) return return_success(object_to_json(book))
def select_video(request): header = get_header(request) video_list = Video.objects.order_by('?')[:10].values() return return_success(list(video_list))
def add_joke_api(request): add_joke() return return_success('保存成功')
def add_news_api(request): add_news() return return_success('保存成功')