In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you an example analysis of the Django implementation of the first request, which is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Request flow of Django
Write urls.py add request routing from import viewsurlpatterns = [path ('admin/', admin.site.urls), path (' test/', views.test_path), # add the request path and the function handled by the request] write the views.py under the application directory
Increase the processing logic of the corresponding request
From django.shortcuts import render,HttpResponse # Import HttpResponse module def test_path (resquest): # function name should be consistent with the print (dir (resquest)) return HttpResponse in urls.py ("first Django request") # return properties related to the content to the page view request
Request.method-- > returns the requested method (in all uppercase): GET/POST.
Request.GET-- > getting is a parameter in URL, similar to the data structure of a dictionary
Request.POST-- > data submitted by post, similar to the data structure of a dictionary
There are three ways to return a page: `from django.shortcuts import HttpResponse, render, redirect`
HttpResponse returns a specified string
Render returns a HTML file, return render (request, 'index.html')
Redirect jumps to the corresponding URL,return redirect ('/ index/')
Send data to the page
Return render (request, 'login.html', {' error_msg': error_msg}), you can use {{variable name}} to get data on the page
test
After starting the project, the test results in the browser are as follows:
The above is a sample analysis of the first request implemented by Django. Have you learned any 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.