In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use the Django-3 template, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.
We learned that templates allow us to reuse code snippets in multiple places, making them ideal for dynamic HTML pages. Use a template to return the more complex HTML to the browser. We will also see how to pass variables as context to the template. Let's start with:
Create a new folder templates\ blog under django_project\ blog\ to store all static html pages, and create a new folder static\ blog to store style files, image files, and so on:
Modify django_project\ settings.py and add the configuration of blog:
Modify django_project\ blog\ views.py:
From django.shortcuts import render# defines a list for foreground data display using posts = [{'author':' Liaobei Emperor', 'title':' blog first post', 'content':' blog first post', 'date_posted':' 04 July 2019'}, {'author':' Love Miracle' 'title':' blog second post', 'content':' blog second content', 'date_posted':' 04 July 2019'}]
# define the home page access method def home (request): context = {'posts':posts} return render (request,' blog/home.html', context) # define about the access method def about (request): return render (request, 'blog/about.html')
Create a new style file main.css under django_project\ blog\ static\ blog:
Create a new base.html under django_project\ blog\ templates\ blog to store general blog page template information:
Create a new home.html under django_project\ blog\ templates\ blog, store the content on the first page of the blog, and display a list of posts:
Create a new about.html under django_project\ blog\ templates\ blog to display information about the page:
We run the python manage.py runserver startup project under the django_project folder and access http://127.0.0.1:8000/:
Next, let's visit the http://127.0.0.1:8000/about page about:
The above content is how to use the Django-3 template, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.