Python Bootstrap

View previous topic View next topic Go down

Python Bootstrap

Post by jamied_uk on 17th November 2016, 12:56

Using Bootstrap
Bootstrap is a collection of CSS styles and simple javascript actions that are easily applied to any web page.

The slides you're looking at, as well as the other pages in the course website, are styled using Bootstrap at its most basic application.

Bootstrap styles can be saved locally or accessed dynamically with a network connection. Because I sometimes work offline, I saved them in order to access them locally.

To use local Bootstrap files, download static.zip from the class data page, and unzip in the same directory as your HTML page (the until will create a static folder containing other folders).

In your HTML page, place the following code in your tag (bolded additions are not necessary):


Code:
<head>
 <title>My Webpage, by Y.T.</title>
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <link rel="stylesheet" href="static/css/Bootstrap/bootstrap.min.css">
 <style>
 pre {
 height: auto;
 max-height: 500px;
 overflow: auto;
 }
 </style>
 <script src="static/css/Bootstrap/js/bootstrap.min.js"></script>
 <script>
 function open_window(url) {
 window.open(url);
 }
 </script>
</head>



The bolded portions are additions that I made -- as you can see, it's possible to customize Bootstrap by adding one or more CSS Styles to the same container tag.


To use Bootstrap through a network connection, the tags referencing .css and .js files should look like this:


Code:
[size=20]<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
[/size]


[size=24][/size]



Many themes have been added to and are available through Bootstrap.

The Bootstrap docs provide a clear rundown of what is available both for CSS and Javascript actions.


davidbpython.com/advanced_python/slides/course_slide_2704_sm.html
avatar
jamied_uk
Admin

Posts : 1990
Join date : 2010-05-09
Age : 34
Location : UK

http://address-shortner.co.uk

Back to top Go down

Re: Python Bootstrap

Post by jamied_uk on 17th November 2016, 13:03

Using Flask

Flask: a "lightweight" framework for serving web applications.
Flask uses a simple dispatch mechanism for launching functions based on the URL

hello_flask.py


Code:
from flask import Flask
app = Flask(__name__)      # a Flask object

@app.route('/')            # called when visiting web URL 127.0.0.1:5000/
def hello_world():
    return 'Hello World!<BR><BR>Say <A HREF="/bye">Bye!</A>'

@app.route('/bye')         # called when visiting web URL 127.0.0.1:5000/bye
def goodbye():
    return 'Get thee to a nunnery!<BR><BR>Say <A HREF="/">Hi!</A>'

if __name__ == '__main__':
    app.run(debug=True, port=5000) # app starts serving in debug mode on port 5000





The functions preceded by @app.route() decorators may be called event functions; these are called in response to an event, namely the calling of a URL by the user.

In the simplest application, returning a string from an event function causes Flask to return this string to the browser. (In most cases, the browser will interpret a string as HTML.)

Note the tags that call this app with one or the other page's URL: this app allows you to click a link that flips back and forth between pages.

Flask is among the simplest libraries for writing and serving web applications, and is perfectly suited to a wide range of domains. By contrast, Django is often used for larger-scale websites, although its configuration requirements are more demanding and its learning curve is steeper.

davidbpython.com/advanced_python/slides/course_slide_2801_sm.html

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum