Python Flask implements restful api service and flaskrestful
Node. js is used as the backend and needs to be gradually involved in big data, so it is doomed to bypass python. Therefore, it is decided to rewrite some mature things with python. First, it is a pioneering idea t
Use python + flask to create an api (the source code is included in the tutorial) and pythonflask
1. Background
OK. Maybe many of my friends often use various APIs like facebook, github, and even api. So many people also want to create their own APIs. There are very few tutorials on the Internet. Today I just made a tr
using Python to access the MySQL database under Windows,
data access is provided externally using the Flask Development API interface.
1, view the Python version python-vPython 2.7.12:: Anaconda 4.1.1 (64-bit) 2, install driver Mysql-py
1. BackgroundOK, this may be a lot of friends and I like to use a variety of APIs, examples of Facebook. GitHub's. Even the API. Therefore, many people want to make their own API. Online tutorials In this regard it is very small, and today, I made a smooth, release time under the method.First show the effect:Using the "Curl" method, return a JSON, you can also try:Curl-i HTTP://OSPAFZONE.DUAPP.COM/OSPAFwate
1. BackgroundOk, maybe a lot of friends like me often use a variety of APIs, such as Facebook, GitHub, and even API. So many people also want to make their own API. Online on this aspect of the course is very few, today I have done one, the method published.First show the effect:Using the "Curl" method, return a JSON, you can also try:Curl-i HTTP://OSPAFZONE.DUAPP.COM/OSPAF2. CodeFirst of all, the environme
This article mainly introduces the example of implementing the rest request api in python. if you need it, refer to the Sina python api for reference. it is applicable to open-source api requests.
The code is as follows:
#-*-Co
')Add_argument can specify the name of this field, the data type of the field, and so on. Some of the parameters of this method are explained in detail below:1. Default: Defaults, if this parameter has no value, then the value specified by this parameter will be used.2. Required: Whether it is necessary. The default is False, and if set to True, then this parameter must be submitted. 3. Type: The data type of this parameter, if specified, then the value of the commit will be cast using the speci
Before also wrote Python smtplib send mail, it is based on Smtpmlib module write application, here is to use flask write a simple API, the specific application scenario is, if a LAN environment, only one host can external network outgoing mail. Other hosts are not available outside the network. This host initiates a Flask
registered users. The access point is/api/resource.This is done using the HTTP BASIC authentication method, and I plan to use the Flask-httpauth extension to implement this feature.After importing the Flask-httpauth extension module, add the login_required adorner for the corresponding function:From Flask.ext.httpauth Import Httpbasicauthauth = Httpbasicauth ()
/activate2. Now we need Ganache that ethereum test chain.Ganache is a personal blockchain developed by Ethereum that can be used to deploy contracts, develop applications, and run tests.$ npm install -g ganache-cli3. Install Python web3web3.py is a Python library for interacting with Ethereum. Its API is derived from the Web3.js Javascript
["Predictions"] = []# Loop over the results and add them to the list of# returned predictions for(Imagenetid, label, prob)inchresults[0]: R = {"Label": Label,"Probability":float(Prob)} data["Predictions"].append (R)# indicate that's the request was a successdata["Success"] =True# Return the data dictionary as a JSON responsereturnFlask.jsonify (data)Although it is a core part, it is very easy to be reused. is the process of reading the data and then processing it. # If This is the main thread o
Flask restful api series (1), flaskrestful
Before that, we would like to explain that our entire framework uses flask + sqlalchemy + redis. If you have not developed a web application, let's take a look at it first. Here we will only introduce how to switch from the development web to the development mobile terminal. If you are not familiar with
/activate2. Now we need Ganache that ethereum test chain.Ganache is a personal blockchain developed by Ethereum that can be used to deploy contracts, develop applications, and run tests.$ npm install -g ganache-cli3. Install Python web3web3.py is a Python library for interacting with Ethereum. Its API is derived from the Web3.js Javascript
.
WSGI server: Although Flask has a built-in simple WSGI server, its performance is only applicable to debugging in the development phase. The Flask website recommends a variety of WSGI servers, from multi-process to multi-thread to coroutine, which will not be covered in this course.
REST adaptability: Although Flask
First, to talk about the hole encountered:1. Package references for Linux under:1 """2 The path structure is as follows:3 ./project4 ./bin5 ./api6 """7 #to reference the contents of apilib.py in the API directory under main.py in the bin directory8 ImportSYS9Sys.path.append (".. /")Ten fromApi.apilibImportFunc2. When running large system, the execution directory of the script that you initiated under/root is also/root, so pay attention to the absolut
ready
Before we start, we need to install some Python packs before we can work! We pass? Python Package Manager pip to complete this thing.Pip Install flask Flask-stormpath
The above command installs two packages: Flask, and Flask
.
The final website should look like this:Ready to
Before we start, we need to install some Python packs to work! We're through? Python Package Manager pip to complete the event.Pip Install flask Flask-stormpath
The above command installs two packages: flask, and
Python Flask framework for simple Login
Python Flask framework provides a simple logon tutorial. logon is a basic function in various web frameworks. For more information, see
Review
In the previous series, we created a database and learned to fill it with users and emails, but we have not yet been able to implant it i
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.