Delivery throughout Europe

Ordered before 16:00 = Shipped today

Fast delivery with DHL

XNUMX days return *


Country

During this web server introduction I will show you how to make a simple web server.

This is a simple project where you learn to build a web server that shows text and a photo. The moment you understand HTML more, you can even control lights with it. This is a simple project that you could use as a basis for further web server projects.

  • Level - beginner 40% 40%
  • Duration - 10/15 Min 25% 25%
  • Costs - € 44.48 euros complete 40% 40%

Step 1: Requirements

  • Raspberry Pi 3B+ or Raspberry Pi 4
  • HDMI cable
  • Monitor
  • Mouse & Keyboard

Step 2: Connecting

Now you you Raspberry Pi you need to connect a monitor, keyboard, mouse and power supply to it.

You can easily connect the display via the HDMI connection. The mouse and keyboard can be connected via the USB connections. Finally, you connect the power supply via the micro USB connection.

Step 3: Programming

 

Now that you have connected the power supply, mouse, keyboard and screen, you can start programming.

Programming is done on the Raspberry Pi via the program: Thony Python IDE. This is where you put the first code. The second code is an HTML file, this is the building block of your web server, with which you can make your server do everything the moment you master HTML.

You create this file on the Raspberry Pi using TextEdit. Once you've opened Text Editor, write the code in it the same way as below. If you then save it, name the file webserver.html if you don't do this you will get an error when the server wants to open.

Now that you have finished programming, you must create a folder where the py file and html file are together or you will not be able to boot the server. For the photo it contains you need to create another folder in that folder called images. In it you put the photo, if you do not do this, your photo cannot be loaded.

The moment you have done that open the terminal and type in hostname -I once you do that the ip address of your Raspberry Pi. Once you know that, type “cd (name of your folder with the py and the html file)”. When that is done, your server has started up.

When your server is started you can visit it via the internet. You can do this by entering the IP address in your search bar and then: 3000, for example 0.0.0.0:3000. Now you should have your own web server.

from flask import Flask, send_file

app = Flask('web page')

@app.route('/')
def index():
        return send_file('webserver.html')

@ app.route ('/ images /')
def get_image (filename):
return send_file ('images /' + filename)

app.run (debug = true, port = 3000, host = '0.0.0.0')

Below is the code for the HTML file. The name of the photo I use is logo.png change this to the name of your own photo otherwise it will not work.

<html> <head> <title>web server</title> <arches charset="utf-xnumx"> </head> <body> <h1>Your own raspberry pi web server</h1> <img src="/images/logo.png" alt ”failed to load ”> </body> </html

The rating of www.elektronicavoorjou.nl at WebwinkelKeur Reviews is 9.3/10 based on 4989 reviews.