jagomart
digital resources
picture1_Python For Web Programming


 112x       Filetype PDF       File size 0.05 MB       Source: cs50.harvard.edu


File: Python For Web Programming
cs50python for web programming overview key terms in addition to using python for writing local programs and algorithms python is of server side ten used for web programming in web ...

icon picture PDF Filetype PDF | Posted on 05 Feb 2023 | 2 years ago
Partial capture of text on file.
         CS50Python for Web Programming
        Overview                                                                                          Key Terms
        In addition to using Python for writing local programs and algorithms, Python is of-              •  server-side                        
        ten used for web programming. In web programming, Python is used for server-side                   scripting
        scripting. In other words, it’s used on the back end of a web application to implement            • Flask
        web servers. While Python is one of many languages used for back end web program-                 • web framework
        ming, its readability, simplicity, and convenience all contribute to its popularity. In par-      • micro framework
        ticular, Python has a built in HTTP server library called http.server that includes func-         • Jinja
        tions for listening, managing, and responding to HTTP requests. Because Python has a 
        history of being used for web programming, many external web programming tools are 
        built using and compatible with Python, such as Django and Flask. Python also offers 
        easy integration with other tools and programming languages.
        Flask
        Flask is a micro web framework written in Python that provides programmers with tools to easily and quickly 
        implement web applications. A web framework is software that provides tools, libraries, and extra technologies 
        to build web applications, and a micro framework is a framework that is not highly dependent upon external 
        resources. Because of tools like Flask, it is unnecessary for web programmers today to build web servers from 
        scratch. Instead, by abstracting away lower level details, web programmers can focus on the logic of their specif-
        ic web applications.
        The code on the right shows the Python file of a simple web            from flask import Flask, render_template
        application. In the first line, we import some functionality from 
        the Flask package. Then, we use Flask syntax create a new web  app = Flask(__name__)
        application, allowing Flask to set up some low level details. 
        Below that, we tell our applciation to go to the function index        @app.route(“/”)
        when the “/” route is requested. Within index, we’ve called the        def index():
        Flask function render_template to send the file index.html to              return render_template(“index.html”)
        our user’s browser.
        As you can see, building a web application with Flask is incredibly simple. In addition to this basic functional-
        ity, Flask offers many other features that are useful for building web applications. To use these features, simply 
        check out Flask’s documentation.
                                 layout.html                               Jinja
                                                            Jinja is a template engine built into Flask. One of 
                                                                           its features is a templating language that allows 
                                                                     you to use dynamic elements (variables, loops, 
                                                                     conditions) in static HTML/CSS files. Jinja expres-
                               Hello                        sions are very similar to Python expressions, mak-
                                                                    ing Jinja even more convenient to use. Jinja also 
                                                                     enables inheritance of HTML/CSS files, minimizing 
                               {% block body %}{% endblock %}              rewritten code. 
                        
                                                                    In the code on the left, the file message.html is 
                                                                           using Jinja to inherit code from layout.html. Inheri-
                                message.html                               tance of templates demonstrates better program-
                {% extends “layout.html” %}                                ming design because it reduces repeated code, 
                                                                           maintains consistency, and makes templates more 
                {% block body %}                                           convenient to update.
                        Hello, world!                                      Like Flask, you can learn more about features of 
                {% endblock %}                                             Jinja by looking at the Jinja documentation.
     © 2018                                                                                                          This is CS50.
The words contained in this file might help you see if this file matches what you are looking for:

...Cspython for web programming overview key terms in addition to using python writing local programs and algorithms is of server side ten used scripting other words it s on the back end a application implement flask servers while one many languages program framework ming its readability simplicity convenience all contribute popularity par micro ticular has built http library called that includes func jinja tions listening managing responding requests because history being external tools are compatible with such as django also offers easy integration written provides programmers easily quickly applications software libraries extra technologies build not highly dependent upon resources like unnecessary today from scratch instead by abstracting away lower level details can focus logic their specif ic code right shows file simple import render template first line we some functionality package then use syntax create new app name allowing set up low below tell our applciation go function index...

no reviews yet
Please Login to review.