Our new test.html template will look like this: & #123 % extends "layout.html" %} To pass multiple variables to the function, we simply do this: return render_template( We will need to pass both the name variable and the quote variable. Lets display random quotes instead of always the same quote. Python Flask: Make Web Apps with Python Passing Variables You can pick any name other than Jackson. (You may want to split the stylesheet and layout.html file). We then create layout.html which defines the look of the page. "The limits of my language are the limits of my mind. We have changed the default port to 80, the default HTTP port: from flask import Flask, flash, redirect, render_template, request, session, abortĭo you want some better looking template? We modify the file: & #123 % extends "layout.html" %} The Python Flask app with have a new URL route. We make the directory called /templates/ and create the template: We will separate code and User Interface using a technique called Templates. Python Flask: Make Web Apps with Python Style Flask Pages Restart the application using: $ python hello.py We will now create some URL routes:Ĭopy the code below and save it as app.py from flask import Flask URL Routing makes URLs in your Web app easy to remember. Open in your webbrowser, and “Hello World!” should appear. support for secure cookies (client side sessions)Ĭreate a file called hello.py from flask import Flaskįinally run the web app using this command: $ python hello.py.built in development server and debugger.We’ll use a micro-framework called Flask. In this tutorial you’ll learn how to build a web app with Python.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |