In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "Django how to create a simple web Mini Program". In daily operation, I believe many people have doubts about how Django creates a simple web Mini Program. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how Django creates a simple web Mini Program". Next, please follow the editor to study!
Step 1: create a new web framework program
Go to the folder where you want to create the web program through CMD
Data command django-admin startproject yourhtml
Step 2: modify and add features
Create a specific functional program (app) with the following code
Python manage.py startapp yourapp
Modify the views.py in yourhtml (create it if not) and enter the following code:
From django.shortcuts import renderdef hello (request): return render (request, 'the html' you want to show
What needs to be explained here is that you need to manually create a templates folder under your yourapp folder, and then put in the files you want to display.
In yourapp, add the urls.app file (local route file) and enter the following:
From django.urls import pathfrom. Import viewsurlpatterns = [path ('', views.hello)]
Add the reference to the routing file corresponding to this application in the global routing file yourhtml
There is a pit here, that is, the first parameter urls in path needs to be left empty, otherwise an error will be reported.
Set the template path so that the Django framework can find the corresponding directory of the template
TEMPLATES = [{'DIRS': [os.path.join (BASE_DIR,' yourapp/templates')],}] the third step to debug and run the program
CMD to the root (yourhtml), run:
Python manage.py runserver
The web page will pop up automatically, or click http://127.0.0.1:8000/ to generate the web page.
At this point, the study of "how Django creates a simple web Mini Program" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.