In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces Python+Django how to achieve a simple HelloWord page related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Python+Django how to achieve a simple HelloWord page article will have a harvest, let's take a look at it.
Install Django
Use anaconda to install the Django package in the python environment
Pip install django creates a Django project
Create on the command line using django-admin
Django-admin startproject myproject
Professional version of PyCharm creates django project
Default file
After the project is created, a directory with the same name as the project is generated, as well as a manage.py file
1. Manage.py project management, start the project, create app, data management, this file does not need to be changed
2. In myproject, what we need to write and change are settings.py and urls.py
Urls.py-URL and function correspondence [frequently operated files] settings.py---- project configuration files, such as database connection configuration, static file configuration, APP application configuration, etc., create APP
Large-scale projects generally have many functional divisions. Django will encapsulate these functions in app, that is, without application. Each app has independent functions, static files, etc., and each app does not affect each other.
Python manage.py startapp app
With the above command, you can create an application called app.
Migrations- database changes admin.py- django provides admin background management apps.pymodels.py- for database operations [!! Tests.py- is used to do unit tests. Views.py- defines view functions [! ]
Generally, after creating APP, we need to write views.py function and models.py function, which correspond to URL view function and database operation respectively.
Implement a simple HelloWord web page
First, make sure app is registered.
In the settings.py configuration file, add the app application you created
Write the correspondence between URL and view function
Write correspondence in myproject and view function in views.py of app
App / views.py
From django.shortcuts import renderdef test (request): return render (request,'test.html')
Mypeoject / urls.py
From django.urls import pathfrom app import viewsurlpatterns = [path ('app/test',views.test)]
That is, the test view function corresponding to the app / test route will return a test.html
Start the django project python manage.py runserver 8000
Enter 127.0.0.1:8000/app/test on the web page
This is the end of the article on "how to implement a simple HelloWord web page with Python+Django". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to achieve simple HelloWord web pages with Python+Django". If you want to learn more, 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.