×

Construct Symbol Seek App with Python and Flask

Construct Symbol Seek App with Python and Flask

Construct Symbol Seek App with Python and Flask


In our earlier Python Flask instructional, we now have defined broaden QR Code Generator with Python and Flask. On this instructional, we can give an explanation for broaden Symbol Seek App with Python and Flask.

A picture seek is a seek capability this is applied to search out pictures. The quest will also be in line with key phrases, an image, or a internet hyperlink to a picture.

Right here on this instructional, we can create an consumer pleasant interface for looking out pictures with key phrase and put into effect capability for picture seek the use of Unsplash API with Python and Flask.

So let’s continue with growing Symbol Seek App venture:

1. Mission Setup and Module Set up

First we can create our venture image-search-python-flask listing .


$ mkdir image-search-python-flask

and moved to the venture.


$ cd image-search-python-flask

Then we can set up required modules for our utility. As we can broaden internet primarily based utility, so we can set up Flask micro framework module to create internet utility.


pip set up Flask

2. Create Flask Software

We will be able to create our venture python report app.py and import required modules.


from flask import Flask, render_template, request, redirect, url_for
import sys
import os
import requests

Then we can create our Flask app and run app.


app = Flask(__name__)
app.secret_key = '1234567890'  

if __name__ == '__main__':
    app.run()

3. Create Symbol Seek Shape

Now we can create template report for our flask utility. We will be able to create templates listing in our venture and create index.html template report. Then we can create seek shape to go looking picture with key phrases.




4. Put in force Symbol Seek with API

Then we put into effect serve as index() in app.py and put into effect capability to go looking picture with consumer inputted key phrase. We will be able to test for shape post and get key phrase after which make unsplash API request with params to go looking pictures from API. Then after all go back the hunt end result with to template report to show seek end result.


@app.path('/', strategies=['GET', 'POST'])
def index():    
    searchResult=""
    message=""
    searchQuery = ''
    clientId = 'y4i-BtdyHO0mBSE7BhqVPgCBFhqbaTtruS9oZmyKMho'
    if request.way == 'POST':        
        searchQuery = str(request.shape['searchQuery'])
        if searchQuery:            
            apiUrl="https://api.unsplash.com/seek/pictures"
            params = {'question': searchQuery, 'client_id': clientId}
            reaction = requests.get(apiUrl, params=params, allow_redirects=True)
            searchResult = reaction.json()
        else:
            message="Please input seek key phrase"
    go back render_template('index.html', message = message, searchQuery = searchQuery,searchResult = searchResult)

5. Show Symbol Seek Outcome

In any case, in index.html template report, we can show the hunt end result.


{% if searchResult %} {% for picture in searchResult.effects %}
{% endfor %} {% endif %}

Dwonlaod



Source link

send message
Hello,
Iam Guest Posting Services
I Have 400 sites
Status : Indexed All
Good DA : 40-60
Different Niche | Category
Drip Feed Allowed
I can instant publish
ASAP


My Services :

1. I will do your orders maximum of 1x24 hours, if at the time I'm online, I will do a maximum of 1 hour and the process is
completed.
2. If any of your orders are not completed a maximum of 1x24 hours, you do not have to pay me, or free.
3. For the weekend, I usually online, that weekend when I'm not online, it means I'm working Monday.
4. For the payment, maximum payed one day after published live link.
5. Payment via PayPal account.

If you interesting, please reply

Thank You

Regards,

iwan