#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Question on Flask


    I am trying to build a web interface for a search engine. Here is the part of python code for the search engine.

    When a query is given it gives a list of filenames with its modified date, size and path in json format.

    Code:
    def GetOutput(Query):
        Terms = Query.split(' ')
        Result = set()
        WildCardResults = set()
        PhraseQueryResults = set()
        BooleanQueryResults = set()
           
                
        if BooleanTerms != []:
            BooleanQueryResults = GetBooleanResults(' '.join(BooleanTerms))
           
       
        if BooleanTerms != []:
            if PhraseQueries != []:
                if WildCardTerms != []:
                    Result = 
    #somepart of the code removed 
    
         return result
            
    def main():   
       
        Docs_Directory =  'C:\\Users\\.....'
        CreateIndex(Docs_Directory)
        WriteIndexesToFile()
        print "Please enter a query!! Type 'Exxit' to Exit"
        while True:
            Query = stdin.readline()
            Query = Query.strip().lower()
            if Query == 'exxit':
                break
            ResultSet = GetOutput(Query)
            if ResultSet != set():
                Output = list(ResultSet)
                for path, dirs, files in os.walk(Docs_Directory):
                    R = cmp(Output, files)
                    R =list(set(Output).intersection(set(files))) 
                    #print R
                    for X in R:
                        pathX = os.path.join(path, X)
                        #print pathX
                        size = os.path.getsize(pathX)
                        #print size
                        mtime = os.path.getmtime(pathX)
                        time = datetime.fromtimestamp(mtime).strftime("%d%b%Y")
                        #print X,"", time,"", pathX,"", size,"bytes"
                        X_Json=dict.fromkeys([X],[time,pathX,size])
                          
                        print X_Json                    
                        #ResultsJson = json.dumps(X_Json.items())
                        #open('results.json', 'wb').write(ResultsJson)            
                    
            else:
                print 'No Results found'
        print 'Bye!'
        return
        
       
    
    if __name__ == '__main__':
        main()
    Here is part of flask code where I am trying to integrate with the code but getting error, where index.py is my python file and search.html is the frontend code. I am getting 'View function did not return a response'. I was wondering if anyone can help finding the error.

    Code:
    from flask import Flask, request
    from flask import render_template
    import index
    
    app = Flask(__name__)
    @app.route('/', methods=['GET','POST'])
    def Search():
        if request.method == 'Get':
            try:
                X_Json=index.GetOutput(request.args.get('index'))
                Result = X_Json
                query="You searched for: "+request.args.get('index')
                app.logger.debug(Result)
            except: 
                query=""
                Result=''
            return render_template('Search.html', Result=Result, query=query)
        
    @app.errorhandler(404)
    def page_not_found(error):
        return render_template('pagenotfound.html'), 404
    
    if __name__ == "__main__":
        app.run(debug=True)
    error: File "C:\Python27\lib\site-packages\flask\app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
    File "C:\Python27\lib\site-packages\flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
    File "C:\Python27\lib\site-packages\flask\app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
    File "C:\Python27\lib\site-packages\flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
    File "C:\Python27\lib\site-packages\flask\app.py", line 1478, in full_dispatch_request
    response = self.make_response(rv)
    File "C:\Python27\lib\site-packages\flask\app.py", line 1566, in make_response
    Display the sourcecode for this frameOpen an interactive python shell in this frameraise ValueError('View function did not return a response')
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2010
    Posts
    144
    Rep Power
    4
    Any time you get that error with flask, it means a function that you have exposed (using the @route decorator) did not return a value, and thus there is no response to send to the client.

    Since you've only the Search() function here, it's obviously not returning a response. Why do you think that might be? HINT: what happens when the request method is POST?

IMN logo majestic logo threadwatch logo seochat tools logo