How To Set Up A Simple Website Tabby Mungai, September 14, 2023October 4, 2023 For this simple website it involves making a website without WordPress. We are going to use python language and the Flask environment as the virtual environment. Therefore, it is important to first python into your computer. Also, in respect to this blog the operating system we will focus on windows operating system. Download the latest python version from www.python.org by selecting the program that is compatible with your operating system. Open the cmd, type python –version this should return the version of python installed in your computer. Create A Project Environment For Flask The flask ought to be installed into a virtual environment for this setup we will use venv as our virtual environment that will be installed using VS Code. Create a folder flask_hello then Open VS Code open by navigating (View > Command Palette or (Ctrl+Shift+P) ). The select Python: Create Environment , create the virtual environment in flask_hello workspace. Select venv along with the python environment choose from the dropdown menu.(venv diagram) After creating the virtual environment run Terminal: Create New Terminal or (Ctrl+Shift+`) to create a terminal to activate the virtual environment by running the activation script. Install Flask into the virtual environment. In the VS Code Terminal type the command below. python -m pip install flask Now there is a self-contained environment ready for writing Flask code. Use the Terminal: Create New Terminal activate .venv\Scripts\Activate.ps1 (Windows) Creating A Simple Website In VS Code create an app.py file by File > New. In the file app.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return '<h1>Hello, World!</h1>' This code block imports Flask object from the flask package. The Flask application gives it a name app. A special variable is passed __name__ of the current python module. The app instance handles incoming web requests in addition to sending responses to users. @app.route refers to a decorator responsible for tuning a regular Python function into Flask view function. '/' is passed to @app.route()to signify function will respond requests for URL'/'. Running The Web Application Tell Flask where to find app.py the using FLASK_APP. Also, specify to run application in development mode using FLASK_ENV environment variable (Using set command on windows). Warning: You should not use the development server in a production deployment. The output can be shown below for the URL – http://127.0.0.1:5000/ Route URL users can use to determine what they receive when they visit their web application on the browser. For instance the http://127.0.0.1:5000/ refers to the main route that displays the index page. On the other hand, the http://127.0.0.1:5000/about allude to giving visitors information regarding the web application To add an addition route such as the About, edit the code in app.py from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return '<h1>Hello, World!</h1>' @app.route('/about/') def about(): return '<h3>This is a Flask web application.</h3>' The output of the the additional route can be seen below: Programming
Programming How Create a Tic-Tac-Toe Game Using Python October 6, 2023October 9, 2023 Many say that tic tac toe is impossible to win. However, this does not diminish the fact that tic tac toe to play is highly nostalgic. Creating a tic tac toe Read More
Programming How to Create a GitHub Repository for Your Website October 4, 2023October 5, 2023 Why GitHub is used, it is a platform for hosting code where GitHub actions run in addition to allowing for version control and collaboration. For GitHub job the GitHub workflow are defined by a YAML file that checked into the repository and run when triggered by an event in the repository, the trigger can be manually or within a definite schedule. Read More
Programming How To Create A Web Application Database September 27, 2023October 3, 2023 A database is generally a collection of information that one can store within a centralized location. Therefore, creating a database with python can be instrumental in allowing user input data to a given website. Read More