HTML | Python In HTML Examples https://pythoninhtmlexamples.com Showing You How You Can Use Python On Your Website Wed, 11 Jan 2023 21:52:12 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 194754043 How To Read A CSV Into A HTML Table With Python https://pythoninhtmlexamples.com/how-to-read-a-csv-into-a-html-table-with-python/?utm_source=rss&utm_medium=rss&utm_campaign=how-to-read-a-csv-into-a-html-table-with-python Wed, 11 Jan 2023 21:16:02 +0000 https://pythoninhtmlexamples.com/?p=350 A lot can been done with a CSV (“comma separated value”) file. If you can run a web scraping script on your local machine, you can FTP the results to a FTP site in the ubiquitous CSV format, and then render it on your web page with HTML. The rest of this post demonstrates a […]

The post How To Read A CSV Into A HTML Table With Python first appeared on Python In HTML Examples.]]>
A lot can been done with a CSV (“comma separated value”) file.

If you can run a web scraping script on your local machine, you can FTP the results to a FTP site in the ubiquitous CSV format, and then render it on your web page with HTML.

The rest of this post demonstrates a basic example of how you can read a CSV file into an HTML table using Python.

Add an iframe to your page and point it to your python (py) file:

Here is the code for the file:


#!/usr/bin/python
#import csv  #the module is already present so no need to add it again


#MAKE SURE THE FILE PERMISSIONS ARE 755!!!!

filename = open('file_to_ftp.csv') 


# print HTTP header
print "Content-type: text/html\n\n"

# define an HTML template
print "<!DOCTYPE html>"
print "<html>"
print "<head>"
print "<title>CSVParse</title>"
print "</head>"
print "<body>"

print("<table style='width:100%'>")

print("<tr>")
print("<th>Index</th>")
print("<th>Company</th>")
print("<th>Link</th>")
print("<th>Header</th>")

print("</tr>")

for line in filename:	
    row = line.split(",")
    print("<tr>")
    print ("<td>" + str(row[0]) + "</td>")
    print ("<td>" + str(row[1]) + "</td>")
    print ("<td>" + str(row[2]) + "</td>")
    print ("<td>" + str(row[3]) + "</td>")
    print ("</tr>")


print("</table>")


print "</body>"
print "</html>"


Click here for the file in action.

Let me know if you need assistance.

FacebooktwitterredditpinterestlinkedinmailThe post How To Read A CSV Into A HTML Table With Python first appeared on Python In HTML Examples.]]>
350
Python Project – Online Quiz Management https://pythoninhtmlexamples.com/python-project-online-quiz-management/?utm_source=rss&utm_medium=rss&utm_campaign=python-project-online-quiz-management Fri, 25 Sep 2020 18:36:30 +0000 https://pythoninhtmlexamples.com/?p=187 I am going to be implementing some Python projects with a browser front end (obviously since that’s what this domain is called), I am going to be focusing on the core functionality, not really the aesthetics. You can always use some stylesheets (CSS) to make it look pretty. I am just concerned with the fact […]

The post Python Project – Online Quiz Management first appeared on Python In HTML Examples.]]>
I am going to be implementing some Python projects with a browser front end (obviously since that’s what this domain is called),

I am going to be focusing on the core functionality, not really the aesthetics. You can always use some stylesheets (CSS) to make it look pretty.
I am just concerned with the fact that it works.

The first one is going to show you how to implement an Online Quiz Management System.

(Click the image to see it in action – login: demo, 123)

It will have 2 views – Admin view and End User view:

Admin view

Log inClick here for the code
Add/Edit/Delete new quiz text (Click for code)
-Add questions and answers for the selected quiz

End User view

Log inClick here for the code
-Select the quiz to take
-View the question
-Answer the question
-Tally the result at the end.

Setup

First off we need to setup a MySQL database to hold all the persistent data for our application.

Login to your control panel (mine is on the hostgator webserver) and add a database called “online-quiz”

now add an admin user…

If you need some more information or help, see this post (from a hostmonster perspective).

Now it will show up in the database administration tool (phpMyAdmin)

Now we can start adding tables.

The first will be the users table (tblUsers).

FacebooktwitterredditpinterestlinkedinmailThe post Python Project – Online Quiz Management first appeared on Python In HTML Examples.]]>
187
A Brief History Of HTML https://pythoninhtmlexamples.com/a-brief-history-of-html/?utm_source=rss&utm_medium=rss&utm_campaign=a-brief-history-of-html Fri, 17 Apr 2020 20:15:39 +0000 https://pythoninhtmlexamples.com/?p=164 What Is The Concept Of HTML HTML is an acronym for “HyperText Markup Language” and put 2 key concepts together, hypertext and markup language. The language of HTML is used to create documents that use “tags” to determine structure and format. Hypertext provides a way to organize and present data in a way, it’s the […]

The post A Brief History Of HTML first appeared on Python In HTML Examples.]]>
What Is The Concept Of HTML

HTML is an acronym for “HyperText Markup Language” and put 2 key concepts together, hypertext and markup language.

The language of HTML is used to create documents that use “tags” to determine structure and format.

Hypertext provides a way to organize and present data in a way, it’s the first HTML element. It’s purpose is to link documents in a non-linear manner.

Hypertext documents contain active links, aka “pointers, to other informational sources, like other web pages.

The individual using the page and click a link and move to another hypertext area in the same document, or move to another web page altogether.

Microsoft Word uses bookmarks in the document for navigational purposes, also you see that the main idea of the search engine is to provide an index of webpages that link to each other.

One of the reasons for the “World Wide Web’s” incredible growth is because of its intuitive nature. It’s easy to “surf the net” by clicking links on hypertext documents which tie them together.

Hypertext systems are naturally used for navigating and exploring presented information.

The textual term for the linked text is “Hypertext”, and when it pertains to media, like videos, audio, images or other multimedia, we can consider them “Hypermedia”.

Who Came Up With The Idea?

A guy by the name of Ted Nelson came up with the idea for hypertext in 1965. He coined the terms hypertext and hypermedia in 1963 and published them in 1965.

The 1st widely commercialized hypertext product was the HyperCard

The Hypercard was conceived by a fellow named Bill Atkinson, and it was introduced in 1987 by Apple Computer. The application incorporated many hypertext and hypermedia concepts, but was really proprietary and only worked on Mac computers.

According to Wikipedia (https://en.wikipedia.org/wiki/HyperCard):

“HyperCard is a software application and development kit for Apple Macintosh and Apple IIGS computers. It is among the first successful hypermedia systems predating the World Wide Web. HyperCard combines a flat-file database with a graphical, flexible, user-modifiable interface.

HyperCard is based on the concept of a “stack” of virtual “cards”.[5] Cards hold data, just as they would in a Rolodex card-filing device. Each card contains a set of interactive objects, including text fields, check boxes, buttons, and similar common graphical user interface (GUI) elements. Users browse the stack by navigating from card to card, using built-in navigation features, a powerful search mechanism, or through user-created scripts.[6]”

Cross Platform Equivalent

HyperCard was only usable on Apple machines, but “HTML” was and is a cross platform language, which can be used by Microsoft, Apple, Linux, Chromebooks, and all other machines I may have missed.

Also, remember that HTML and the rest of the Web is a client/server system, and Hypercard only works on the Apple Macintosh computer.

FacebooktwitterredditpinterestlinkedinmailThe post A Brief History Of HTML first appeared on Python In HTML Examples.]]>
164
What Is HTML? https://pythoninhtmlexamples.com/what-is-html/?utm_source=rss&utm_medium=rss&utm_campaign=what-is-html Tue, 14 Apr 2020 21:36:36 +0000 http://pythoninhtmlexamples.com/?p=133 HTML – stands for “Hyper Text Markup Language” It’s the basic stuff web pages were written in years ago. Because the web pages were mostly static, this was a way to break up the monotony. You could and some color to your text and change the font size where you wanted. You could even link […]

The post What Is HTML? first appeared on Python In HTML Examples.]]>
HTML – stands for “Hyper Text Markup Language”

It’s the basic stuff web pages were written in years ago. Because the web pages were mostly static, this was a way to break up the monotony. You could and some color to your text and change the font size where you wanted. You could even link to other pages, either related or not related. Pretty cool (for then), now there is something called CSS (Cascading Style Sheets) to store all your web page formatting in one place.

This article will deal with the basics of HTML, and you can use the concepts to apply to CSS.

So when Google came around and had the idea to download the web, basically you could download the web page location (URL), and whatever it linked to, and eventually you would have an listing of all the web pages that linked to each other.

Of course, over time, that algorithm evolved because of ideas, like “what if we categorize the page by what the page is about?”, or “we can base the importance of a site by how many other pages link to it.” etc…

Here are some frequently asked question and answers according to Erik:

What is HTML in simple terms?

HTML is a way of displaying text in a web browser.

You can use HTML to “markup the text” with special tags to format the text the reader is reading.

As I wrote earlier, you can change the color of your text on the screen, or the size of certain letters, or even tell the web browser to show the font as bold, italic, or underlined.

What is HTML used for?

HTML is used to “markup” the plain text on a website and make it nicer to read. It gives you the ability to emphasize certain pieces of text on the screen by giving the text some color, changing the character (font) size, or making some other design changes.

What is HTML and how it works?

HTML uses “tags” which the browser understands to perform a certain action on the text the tags surround. Look for some example tags further down on this post.

What is HTML syntax?:

These are the main tags that you’ll use in your HTML documents. All your html files will have the same structure (4 tags and closing tags):

1. html
2. head
3. title
4. body

Here is an example of HTML syntax:

Notice that is follows a general structure or template, and you can just fill in the template.

<html>
  <head>
    <title></title>
  </head>
  <body>
    <!--this is a comment -->
  </body>
</html>

Here is one example of how HTML syntax can be used.

<font size='24 pts'>This font is 24 pts</font>

This font is 24 pts

*********************************************************************

Here are some other tags:

this is a ordered (numbered) list

  1. Subaru
  2. Honda
  3. Toyota
  4. BMW

this is a unordered (bulleted) list

  • Subaru
  • Honda
  • Toyota
  • BMW

these are paragraphs (1 blank line between each paragraph)

Paragraph 1

Paragraph 2

Paragraph 3

these are line breaks (normally it’s like pressing the “Enter” key on your keyboard) (but since this is WordPress, you will see the same effect as the “p” tag)
Line 1

Line 2

Line 3

<html>
  <head>
    <title>The Title Of This Page Is</title>
  </head>
  <body>
    <!--this is a (comment) ordered (numbered) list -->
    <ol>
      <li>Subaru</li>
      <li>Honda</li>
      <li>Toyota</li>
      <li>BMW</li>
    </ol>
    
    <!--this is a (comment) unordered (bulleted) list -->
    <ul>
      <li>Subaru</li>
      <li>Honda</li>
      <li>Toyota</li>
      <li>BMW</li>
    </ul>

    <p>
    Paragraph 1
    </p>
    
    <p>
    Paragraph 2
    </p>

    <p>
    Paragraph 3
    </p>
    
    Line 1
    <br>
    Line 2
    <br>
    Line 3
        
        
  </body>
</html>

*********************************************************************
HTML is:

-A platform independent language (main platforms (that I know exist), windows, mac, linux, android, iphone, chromebook).
-HTML is not case sensitive language (upper and lower case, it’s all good :)).
-HTML allows you to define the page title, Ordered and unordered lists, defining paragraphs and line breaks, etc.
-HTML can controls fonts, colors, and positioning
-Using HTML we can build tables.

How do browsers work?

Browser’s work by rendering HTML marked up text files. The browser understands that files with a .htm or .hhml extension are web files that can be rendered by the web browser in rich text.

Is HTML coding?

HTML is not scripting or coding. It just marks up text.

We can use something like Javascript to code what the user’s desktop experience will be, and we can use Python or PHP to code for the server and make database connections, and activities.


We will be offering other examples in future articles.

FacebooktwitterredditpinterestlinkedinmailThe post What Is HTML? first appeared on Python In HTML Examples.]]>
133
Simple Python Variables Examples https://pythoninhtmlexamples.com/simple-python-variables-examples/?utm_source=rss&utm_medium=rss&utm_campaign=simple-python-variables-examples Fri, 05 Jul 2019 17:36:21 +0000 http://pythoninhtmlexamples.com/?p=49 In this post I am going to show you 2 simple ways of using variables in your python html files. The 1st way is using a text, string, variable #!/usr/bin/python msg='Python Text Variable.' print "Content-type: text/html\n\n"; print "<html><head>"; print "<title>Simple Python Text Variable</title>"; print "</head><body>"; print "<p>" + msg + "</p>"; print "</body></html>"; Here is […]

The post Simple Python Variables Examples first appeared on Python In HTML Examples.]]>
In this post I am going to show you 2 simple ways of using variables in your python html files.

The 1st way is using a text, string, variable

#!/usr/bin/python

msg='Python Text Variable.'

print "Content-type: text/html\n\n";
print "<html><head>";
print "<title>Simple Python Text Variable</title>";
print "</head><body>";
print "<p>" + msg + "</p>";
print "</body></html>";

Here is a working example:

http://pythoninhtmlexamples.com/files/python_text_variable.py

Way number 2 is to use a integer in your html file:

#!/usr/bin/python

n1 = 2
n2 = 4

#here I am casting my variables as an integer (numeric) value so I can calculate them.
total= (int(n1) * int(n2))

print "Content-type: text/html\n\n";
print "<html><head>";
print "<title>Multiplication Of Numbers </title>";
print "</head>";
print "<body>";

#to print out the total variable I have to convert the integer value into a string variable.
print "<p>total= " + str(total) + "</p>";
print "</body>";
print "</html>";

Here is a working example:
http://pythoninhtmlexamples.com/files/simple_math.py

PS. if your file constantly gives you an error, and your syntax is totally correct, and you are about to throw the computer across the room in frustration 🙂 , make sure you set your file permissions to 755.

FacebooktwitterredditpinterestlinkedinmailThe post Simple Python Variables Examples first appeared on Python In HTML Examples.]]>
49