![]() |
A lightweight web framework in Python that converts small web apps to large web apps is called Pyramid. There are various circumstances when the user needs to add some images, HTML code, CSS code, etc. along with the Python code in the web app. These are called static assets and can be added using the Pyramid in Python. Python Pyramid – Static Assets
The ‘static’ directory is used to store the static assets. There are three static assets in Python Pyramid:
Static Asset: ImageThe visual representation of something is called an image. It is very crucial to add images to the app to make it attractive. In this way, we will see how we can add static assets, and images to the web app using Pyramid. app2.pyIn this example, we created a Python file app2.py under the package pyramid1. We have defined a constructor in the app in which we have added the static view. Python3
home.jinja2Now, we have created a folder templates under static. In this templates folder, we have created the home.jinja2 file. In this file, we have defined the static asset image that we want to display on our web app. HTML
horje.pngHere, we have used the Geeks For Geeks logo (link) as an image, which we have placed in the static folder. Thus, the package will look similar to this: Output: Now, run the following command in the terminal to run the app. python app2.py
For seeing the webapp, open the browser of your choice, and type the URL, http://localhost:6543/ Static Asset: CSS FileThe way of displaying HTML elements in known as CSS. It is very crucial to add CSS in web app for making it attractive. In this way, we will see how we can add static asset: CSS to the web app using Pyramid. app2.pyIn this example, we created a Python file app2.py under the package pyramid1. We have defined a constructor in the app in which we have added the static view. Python3
home.jinja2Now, we have created a folder templates under static. In this templates folder, we have created the home.jinja2 file. In this file, we have defined the static asset CSS that we want to display on our web app. HTML
style1.cssHere, we have created the CSS file style1.css in the static folder. CSS
The package will look similar to this: Output: Now, run the following command in the terminal to run the app. python app2.py For seeing the webapp, open the browser of your choice, and type the URL, http://localhost:6543/ Static Asset: Javascript FileJavascipt is the most popular light-weighted programming language. It helps in making the web app reponsive. In this way, we will see how we can add static asset: javascript to the web app using Pyramid. app2.pyIn this example, we created a Python file app2.py under the package pyramid1. We have defined a constructor in the app in which we have added the static view. Python3
home.jinja2Now, we have created a folder templates under static. In this templates folder, we have created the home.jinja2 file. In this file, we have defined the static asset Javscript that we want to display on our web app. HTML
function.jsHere, we have created the Javascript file function.js in the static folder. Javascript
The package will look similar to this: Output: Now, run the following command in the terminal to run the app. python app2.py For seeing the webapp, open the browser of your choice, and type the URL, http://localhost:6543/ ConclusionThe static assets are used to make the web-app look attractive and reponsive. I hope after reading the above article, you will able to use the static assets in your Pyramid web app. |
Reffered: https://www.geeksforgeeks.org
Geeks Premier League |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |