In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Python framework Django page rendering and database application is how, I believe that many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Django environment to build and create projects, just output a line of characters, you can add content and rendering to the page, of course, you need to have a certain amount of html, CSS and other front-end knowledge. Here is a simple rendering of the output characters.
page rendering
We need to diversify the page, then we use html format files, we first create a new index.html file in the templates directory, if there is no templates directory, you can create it first. Then right-click on the directory and create an HTML File. I want to change the font color to blue, the reference code in index.html is as follows:
test
Hello pk
Modify the output content in views.py under pk module, comment out the pure string output in the previous article, and change it to output the content in index.html.
Also add the path to templates in settings.py so that the service knows where the index.html file is, and if the path information exists, don't modify it.
Restart the service, refresh the page to see the page effect, the font changed to blue we set.
Here is just a simple example, more front-end knowledge points everyone to recharge after class, there are diversified front-end pages, but the page can not save any data, once the page is closed, the information entered by the user will disappear, then we need to use the database. Django operates on databases through its own ORM framework and natively supports lightweight sqlite3 databases. Open settings.py to see the default configuration of the database, the default configuration is sqlite3, beginners use this is enough, this configuration does not need to be changed. Next we'll use this lightweight database to store Django's user data.
module registration
Before using the database, we need to register the module at settings.py so that the database knows which module is calling it. Add the module "pk" we need to register to INSTALLED_APPS list.
Generally, INSTALLED_APPS includes the following Django native apps by default:
django.contrib.admin--admin site, you'll be using it soon.
django.contrib.auth --authentication authorization system.
django.contrib.contenttypes --contenttype framework.
django.contrib.sessions --session framework.
django.contrib.messages --Message frames.
django.contrib.staticfiles --A framework for managing static files.
These apps are enabled by default to facilitate general projects.
create the data table
Some apps that are turned on by default require at least one data table, so you need to create some tables in the database before you can use them. In the Terminal window below Pycharm, execute the following command:
python3 manage.py migrate
Django comes with a WEB background, below to create WEB background username and password, password input invisible, need to enter twice.
D:\PycharmProjects\mysite>python3 manage.py createsuperuser
Username (leave blank to use 'administrator'): pk
Email address: xxxx@qq.com
Password:
Password (again):
This password is too short. It must contain at least 8 characters.
This password is entirely numeric.
Bypass password validation and create user anyway? [y/N]: y
Superuser created successfully.
After the administrator account password is set, run the command to start the service.
python3 manage.py runserver
Login Management Page
Open admin URL and you can log in with the administrator account and password you just set. After logging in, you can manage the addition and deletion of user accounts, so as to jointly develop a Django project.
After reading the above, do you know how to render pages and database applications in Python framework Django? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!
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.