Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // search.js
- window.onload = boot;
- const ID_SEARCH_EXP = "id_search_exp",
- ID_CHECK_REDIRECT = "id_check_redirect",
- ID_BTN_SEARCH = "id_btn_search";
- var oSearchExp, oCheckRedirect, oBtnSearch;
- function id(pId) {
- return document.getElementById(pId);
- }//id
- function boot(){
- oSearchExp = id(ID_SEARCH_EXP);
- oCheckRedirect = id(ID_CHECK_REDIRECT);
- oBtnSearch = id(ID_BTN_SEARCH);
- var relevant=[
- oSearchExp,
- oCheckRedirect,
- oBtnSearch
- ]
- for (r of relevant) {
- if (r == null) {
- window.alert("Relevant object NOT available. Aborting");
- return;
- }
- }//for
- //window.alert("All relevant objects OK.");
- oBtnSearch.onclick = go_search;
- }//boot
- function go_search(){
- q = oSearchExp.value
- search_url =
- "https://www.google.com/search?q="+q;
- bRedirect = oCheckRedirect.checked
- if(bRedirect){
- document.location.href = search_url;
- }
- else{
- window.alert("Not implemented");
- }
- }//go_search
- ***********************
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>My search app with memory</title>
- <!-- ok for local, not ok for web app
- script src="../static/search.js"
- -->
- <script src=
- "{{ url_for('static', filename='search.js') }}">
- </script>
- </head>
- <body>
- <form>
- <fieldset>
- <legend>What and how to search</legend>
- <label for="id_search_exp">
- Search expression:
- </label>
- <input id="id_search_exp"
- type="text"
- placeholder="search for something"
- size="32"
- name="name_search_exp">
- <br>
- <label for="id_check_redirect">
- Redirect to search engine raw results
- </label>
- <input id="id_check_redirect"
- name="name_check_redirect"
- type="checkbox"
- checked>
- <input type="button"
- id="id_btn_search"
- value="go search">
- </fieldset>
- </form>
- <!-- conditional zone for the NO redirect case -->
- </body>
- </html>
- ******
- # application.py
- # the filename MUST BE application.py
- # for easy AWS EBS deployment
- from flask import Flask, \
- request, render_template, \
- redirect
- application = Flask(__name__)
- @application.route("/", methods=['GET', 'POST'])
- def root():
- return render_template(
- "search2.html"
- )
- # def root
- def receive_user_data():
- bGET:bool = request.method=='GET'
- bPOST:bool = request.method=='POST'
- user_data:dict = request.args if bGET \
- else request.form
- # user_data
- # def receive_user_data
- bCLI = __name__ == '__main__'
- if(bCLI):
- # caution: force IP and PORT only on local dev
- application.run(
- #host="0.0.0.0",
- #port=5000, # default port
- debug=True
- )
- # if
Advertisement
Add Comment
Please, Sign In to add comment