In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to analyze the modularization in web development 7, I believe that many inexperienced people do not know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Data return in json format is supported:
Example:
There is a problem. The web page is not in json format.
Def jsonify (* * kwargs):
Content = json.dumps (kwargs)
# response = Response ()
# response.content_type = "application/json"
# response.body ='{} '.format (content) .encode ()
# return response
Return Response (body=content, status='200 OK', content_type='application/json', charset='utf-8')
@ py.register_postinterceptor
Def showjson (ctx, request, response):
Body = response.body.decode ()
Return jsonify (body=body)
Modularity:
1. Familiar with the programming interface of wsgi
2. Strengthen the idea of modularization and class encapsulation.
3. Enhance the ability to analyze business
In addition, permission verification and SQL injection detection functions use interceptor filtering
VER1:
New-- > Python Package,webtest, put the code in the _ _ init__.py file, and change the Application class to the WebTest class
Import webtest
Webtest. # after this adjustment, in this way, a lot of things are external.
VER2:
Webtest/ {web.py, _ _ init__.py}
1. Put the code after the WebTest class into _ _ init__.py
2. In the WebTest class, add:
Class WebTest:
Router = _ Router # exposes the class in the form of class attributes, as implemented by many basic classes
Request = Request
Response = Response
From webtest import WebTest
WebTest. # in this way, you can access the _ Router class, Requst class and response class in web.py
Publish:
Example:
From distutils.core import setup
Setup (name='webtest'
Version='0.0.1'
Description='wsgiref web test'
Author='jowin'
Author_email='jowin@163.com'
Url=' https://blog.51cto.com/jowin',
Packages= ['webtest'] # packing list, specifying that' webtest' will package all non-catalog submodules in webtest
)
Pip install webtest-0.0.1.zip # is installed on other hosts
VER3:
1. Create a new python package,webtest2/ {web.py,__init__.py}
2. Put all the code into web.py
2. Write only in _ _ init__.py:
From. Web import Application # package uses its own relative path. Webtest2 this package exposes only Application. The package is encapsulated for you through Application. Indirect access
On the left side of pycharm after pip install webtest-0.0.2.zip # installation, there is a conflict between the working directory webtest2 and External Libraries/site-packages/webtest2, but there is a search order; alternatively, the working directory webtest2 can be copied directly to other hosts to run
After reading the above, have you mastered how to analyze the modularization method in web Development 7? If you want to learn more skills or want to know more about it, you are welcome to follow 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.