def index(): if request.method == 'POST': if not current_user.is_authenticated: return redirect(url_for('index')) # 获取表单的数据 title = request.form.get('title') content = request.form.get('content') author = request.form.get('author') pubdate = request.form.get('pubdate') # 验证title,year不为空,并且title长度不大于60,year的长度不大于4 if not title or not pubdate or len(pubdate) > 4 or len(title) > 60: flash('输入错误') # 错误提示 return redirect(url_for('index')) # 重定向回主页 movie = Ariticles(title=title, content=content, author=author, pubdate=pubdate) # 创建记录 db.session.add(movie) # 添加到数据库会话 db.session.commit() # 提交数据库会话 flash('数据创建成功') return redirect(url_for('index')) movies = Ariticles.query.all() return render_template('index.html', movies=movies)
def forge(): db.create_all() name = "Bel" movies = [ { 'title': '杀破狼', 'content': '正经八百看看揭不开锅', 'author': 'Belmod', 'pubdate': '2020_02_29 12:52:09.337867' }, { 'title': '小鬼当家', 'content': '正经八百看看揭不开锅', 'author': 'zhangsan', 'pubdate': '2020_02_29 12:52:09.337867' }, ] user = User(name=name) db.session.add(user) for m in movies: movie = Ariticles(title=m['title'], content=m['content'], author=m['author'], pubdate=m['pubdate']) db.session.add(movie) db.session.commit() click.echo('数据导入完成')
def aaa(): db.create_all() name = "mrliu" articles = [{ 'title': '杀破狼', 'content': '2003', 'pubdate': '2000' }, { 'title': '扫毒', 'content': '2018', 'pubdate': '2000' }, { 'title': '捉妖记', 'content': '2016', 'pubdate': '2000' }, { 'title': '囧妈', 'content': '2020', 'pubdate': '2000' }, { 'title': '葫芦娃', 'content': '1989', 'pubdate': '2000' }, { 'title': '玻璃盒子', 'content': '2020', 'pubdate': '2000' }, { 'title': '调酒师', 'content': '2020', 'pubdate': '2000' }, { 'title': '釜山行', 'content': '2017', 'pubdate': '2000' }, { 'title': '导火索', 'content': '2005', 'pubdate': '2000' }, { 'title': '叶问', 'content': '2015', 'pubdate': '2000' }] user = User(name=name) db.session.add(user) for a in articles: article = Ariticles(title=a['title'], content=a['content'], author='mrliu', pubdate=a['pubdate']) db.session.add(article) db.session.commit() click.echo('数据导入完成')
def append(): if request.method == 'POST': title = request.form['title'] content = request.form['content'] user = User.query.first() ariticles = Ariticles(title=title, content=content, author=user.name) # 创建记录 db.session.add(ariticles) # 添加到数据库会话 db.session.commit() # 提交数据库会话 flash('添加文章成功') return redirect(url_for('index')) return render_template('append.html')
def forge(): db.create_all() name = "Bruce" ariticles = [ {'title':'张恒家','author':'张恒','pubdate':'2020.03.01','content':'张恒牛皮'}, {'title':'2','author':'2','pubdate':'2','content':'2'}, {'title':'3','author':'3','pubdate':'3','content':'3'}, {'title':'4','author':'4','pubdate':'4','content':'4'}, {'title':'5','author':'5','pubdate':'5','content':'5'} ] user = User(name=name) db.session.add(user) for m in ariticles: ariticle = Ariticles(title=m['title'],author=m['author'],pubdate=m['pubdate'],content=m['content']) db.session.add(ariticle) db.session.commit() click.echo('数据导入完成')
def forge(): db.create_all() name = "Bruce" movies = [ {'title': '流浪地球','content':"小破球的流浪史" ,'author':'吴京','pubdate': '2019'}, {'title': '我和我的祖国','content':"开国大典升旗准战" ,'author':'吴京','pubdate': '2020'}, {'title': '杀破狼2','content':"弘扬正义警匪大战" ,'author':'吴京','pubdate': '2015'}, {'title': '战狼','content':"小人物拯救国家和民族命运" ,'author':'吴京','pubdate': '2015'}, ] user = User(name=name) db.session.add(user) for m in movies: movie = Ariticles(title=m['title'], content=m['content'], author=m['author'],pubdate=m['pubdate']) db.session.add(movie) db.session.commit() click.echo('数据导入完成')
def setUp(self): # 更新配置 在开发和配置的时候通常配置不一样 app.config.update( TESTING=True, # 开启测试模式 出错的时候不会输出多余信息 SQLALCHEMY_DATABASE_URI= 'sqlite:///:memory:' # SQLite内存性数据库,不会干扰开发时使用的数据库文件 ) # 创建数据库和表 db.create_all() # 创建测试数据,一个用户,一个电影信息 user = User(name='Test', username='******') user.set_password('123456') movie = Ariticles(title='请问', content='请问') db.session.add_all([user, movie]) db.session.commit() self.client = app.test_client() # 创建测试客户端(模拟客户端请求) self.runner = app.test_cli_runner() # 创建测试命令运行器(触发自定义命令)
def forge(): db.create_all() articles = [ {'title': '微信小程序入门讲解', 'content': 'linux里共有以下几类文件,分别为目录(directory)、(普通)文件(file)、链接文件(link file)、块设备(block)、字符设备(character)、管道文件(pipe)、套接字文件(sockt),灰色标记文件可先忽略。然后文件属性跟windows一样有最新修改时间、文件的大小、所属用户、所属组、文件的操作权限(读入、写入、执行)等,我们可以用下面的命令查看当前目录下的文件的类型及文件属性。', 'author_id': 1}, {'title': 'linux下添加环境变量', 'content': '输出:/home/geeksongs/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.UbuntuonWindows_1804.2019.521.0_x64__79rhkp1fndgsc:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Intel/WiFi/bin/:/mnt/c/Program Files/Common Files/Intel/WirelessCommon/:/mnt/c/Program Files (x86)/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Program Files/Intel/Intel(R) Management Engine Components/DAL:/mnt/c/Users/THINK/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Python 3.8:/mnt/c/Users/THINK/AppData/Local/Programs/Python/Python38:/mnt/c/Users/THINK/AppData/Local/Programs/Python/Python38/Scripts:/mnt/c/Users/THINK/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/THINK/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin里面具有这个环境变量,第一个就是我们刚刚添加的文件夹目录,则环境变量添加成功!!', 'author_id': 1} ] name = "陈亚飞" username = '******' user = User(name=name, username=username) user.set_password('123123') db.session.add(user) for m in articles: article = Ariticles(title=m['title'], content=m['content']) db.session.add(article) db.session.commit() click.echo('数据导入完成')
def index(): if request.method == 'POST': if not current_user.is_authenticated: return redirect(url_for('index')) # 获取表单的数据 title = request.form.get('title') content = request.form.get('ckeditor').replace(' ', '') # 验证title,content,并且title长度不大于60,content的长度不小于10 if not title or not content or len(content) < 10 or len(title) > 60: flash('输入错误') # 错误提示 return redirect(url_for('index')) # 重定向回主页 article = Ariticles(title=title, content=content) # 创建记录 db.session.add(article) # 添加到数据库会话 db.session.commit() # 提交数据库会话 flash('数据创建成功') return redirect(url_for('index')) articles = Ariticles.query.all() return render_template('index.html', articles=articles)
def add(): if request.method == 'POST': title = request.form.get('title') content_ = request.form.get('content') content_2 = content_.replace('<p>', '') content = content_2.replace('</p>', '') author = request.form.get('author') pubdate = request.form.get('pubdate') # 验证title,year不为空,并且title长度不大于60,year的长度不大于4 if not title or not content or not author or not pubdate or len( title) > 20 or len(author) > 10: flash('输入错误') # 错误提示 return redirect(url_for('add')) # 重定向回添加 Ariticle = Ariticles(title=title, content=content, author=author, pubdate=pubdate) # 创建记录 db.session.add(Ariticle) # 添加到数据库会话 db.session.commit() # 提交数据库会话 flash('数据创建成功') return redirect(url_for('index')) return render_template('add.html')
def add(): if request.method == 'POST': if not current_user.is_authenticated: return redirect(url_for('index')) # 获取表单的数据 title = request.form.get('title') author = request.form.get('author') pubdate = request.form.get('pubdate') content = request.form.get('content') # 验证不为空 if not title or not author or not pubdate or not content or len(author)>6 or len(title)>60: flash('输入错误') # 错误提示 return redirect(url_for('index')) # 重定向回主页 ariticle = Ariticles(title=title,author=author,pubdate=pubdate,content=content) # 创建记录 db.session.add(ariticle) # 添加到数据库会话 db.session.commit() # 提交数据库会话 flash('数据创建成功') return redirect(url_for('index')) return render_template('add.html')
def add(): if request.method == 'POST': if not current_user.is_authenticated: return redirect(url_for('index')) # 获取表单数据 title = request.form.get('title') content = request.form.get('content') author = request.form.get('author') # 验证各字段不为空,并且title长度不大于60,pubdate长度不大于8 if not title or not content or not author: flash('输入错误') # 错误提示 return redirect(url_for('add')) # 重定向返回主页 movie = Ariticles(title=title, content=content, author=author) # 创建记录 db.session.add(movie) # 添加到数据库会话 db.session.commit() # 提交数据库会话 flash('数据创建成功') return redirect(url_for('index')) movies = Ariticles.query.all() return render_template('add.html', movies=movies)
def forge(): db.create_all() name = "lv" movies = [ { 'title': '杀破狼', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '扫毒', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '捉妖记', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '囧妈', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '葫芦娃', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '杀破狼', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '扫毒', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '捉妖记', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '囧妈', 'content': '这是一篇文章', 'author': 'lv' }, { 'title': '葫芦娃', 'content': '这是一篇文章', 'author': 'lv' }, ] user = User(name=name) db.session.add(user) for m in movies: ariticles = Ariticles(title=m['title'], content=m['content'], author=m['author']) db.session.add(ariticles) db.session.commit() click.echo('数据导入完成')