当前位置: 首页 > news >正文

东莞设计公司有哪些seocms

东莞设计公司有哪些,seocms,荥阳网络推广公司,建设国家标准官方网站摆上中文版官方文档网站:https://flask.github.net.cn/quickstart.html 开启实验之路~~~~~~~~~~~~~ from flask import Flaskapp Flask(__name__) # 使用修饰器告诉flask触发函数的URL,绑定URL,后面的函数用于返回用户在浏览器上看到的内容…

摆上中文版官方文档网站:https://flask.github.net.cn/quickstart.html
开启实验之路~~~~~~~~~~~~~

from flask import Flaskapp = Flask(__name__)
# 使用修饰器告诉flask触发函数的URL,绑定URL,后面的函数用于返回用户在浏览器上看到的内容
# 注意 route() 内的URL后面带`/`和不带`/`是有区别的,Flask是可以区分的,不能混用,否则访问网页时返回是错的
@app.route('/12/')
def helloWorld():return 'Hello World!'@app.route('/12')
def test():return 'test 12!'if __name__ == '__main__':# run 参数 host="0.0.0.0"代表服务器被公开访问,port=5000设定访问的接口app.run(host="0.0.0.0", port=5000)

引入URL变量
通过把 URL 的一部分标记为 <variable_name> 就可以在 URL 中添加变量。标记的 部分会作为关键字参数传递给函数。通过使用 converter:variable_name ,可以 选择性的加上一个转换器,为变量指定规则

@app.route('/user/<username>')
def show_user_profile(username):# show the user profile for that userreturn 'User %s' % escape(username)@app.route('/post/<int:post_id>')
def show_post(post_id):# show the post with the given id, the id is an integerreturn 'Post %d' % post_id@app.route('/path/<path:subpath>')
def show_subpath(subpath):# show the subpath after /path/return 'Subpath %s' % escape(subpath)

转换器的类型:

string(缺省值)接受任何不包含斜杠的文本
int接受正整数
float接受正浮点数
path类似string,但可以包含斜杠
uuid接受UUID字符串

动态构建URL, url_for()

from flask import Flask, url_forapp = Flask(__name__)@app.route('/')
def index():return 'index'@app.route('/login')
def login():return 'login'@app.route('/user/<username>')
def profile(username):return '{}\'s profile'.format(username)with app.test_request_context():print(url_for('index'))print(url_for('login'))print(url_for('login', next='/'))print(url_for('profile', username='John Doe'))

这个只是打印出URL而已,并不会发起请求

使用 HTTP方法
缺省情况下,一个路由只回应 GET 请求。 可以使用 route() 装饰器的 methods 参数来处理不同的 HTTP 方法:

from flask import request, Flaskapp = Flask(__name__)@app.route('/login', methods=['GET', 'POST'])
def login():if request.method == 'POST':return do_the_login()else:return show_the_login_form()def do_the_login():return "do the loging"def show_the_login_form():return "show the login from"app.run()

静态文件:
动态的 web 应用也需要静态文件,一般是 CSS 和 JavaScript 文件。理想情况下你的 服务器已经配置好了为你的提供静态文件的服务。但是在开发过程中, Flask 也能做好 这项工作。只要在你的包或模块旁边创建一个名为 static 的文件夹就行了。 静态文件位于应用的 /static 中。
使用特定的 ‘static’ 端点就可以生成相应的 URL
url_for('static', filename='style.css')
这个静态文件在文件系统中的位置应该是 static/style.css 。

渲染模板:
使用 render_template() 方法可以渲染模板,你只要提供模板名称和需要 作为参数传递给模板的变量就行了。Flask 会在 templates 文件夹内寻找模板。因此,如果你的应用是一个模块, 那么模板文件夹应该在模块旁边;如果是一个包,那么就应该在包里面(模板参考 Jinja2,https://jinja.palletsprojects.com/en/3.1.x/templates/)

from flask import render_template@app.route('/hello/')
@app.route('/hello/<name>')
def hello(name=None):return render_template('hello.html', name=name)
http://www.yidumall.com/news/31525.html

相关文章:

  • 网站建设 电子商务 品牌首选IDC百度一下网页版搜索引擎
  • 政府网站建设申请报告如何制作一个网页链接
  • 梅州免费建站公司手机推广软文
  • 论坛类网站设计百度搜索指数排行榜
  • 国外源代码网站线上推广有哪些
  • wordpress域名网站搬家淘宝推广怎么做
  • 移动端官网青岛官网seo公司
  • .mil 域名网站有哪些seo排名优化怎样
  • 免费的网站开发平台淮北网站建设
  • 企业建设网站的重要性企业建站
  • 公司备案网站负责人是谁google搜索网址
  • 毛网商城宁波seo推广外包公司
  • 想制作自己的网站在线培训系统平台
  • 自己怎么做云购网站吗北京网站优化方法
  • 拍卖行 网站建设seo推广岗位职责
  • 惠州网站建设 鑫经典软文案例分析
  • 诚信通网站怎么做外链什么是seo搜索引擎优化
  • 同仁微网站建设工作室百度人工智能开放平台
  • 网站手机端跳转页面模板微信营销系统
  • 垃圾ip段做网站百度推广登陆入口官网
  • 如何做自己微网站国际新闻最新消息美国
  • 个人做旅游网站营销模式有几种
  • 湛江北京网站建设保定seo推广外包
  • 有做销售产品的网站免费的关键词挖掘工具
  • 晋城网站制作公司怎么选seo优化外链平台
  • 做一家算命的网站信息流广告案例
  • 云南网站优化360优化大师最新版下载
  • 网站域名解析后多久能生效推广引流方法与渠道
  • 网站建设优点seo搜索引擎优化公司
  • 创意广告宣传片制作seo谷歌外贸推广