Skip to content
Permalink
main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
from flask import Blueprint, render_template,url_for, redirect, jsonify, request,Flask
import requests
# import requests
views = Blueprint(__name__, "views")
app = Flask(__name__)
@views.route("/")
def home():
# return "hello testing"
return render_template("index.html")
# add /views/profile/username
# http://127.0.0.1:8000/views/profile/username
# @views.route("/profile/<username>")
# def profile(username):
# # return "hello testing"
# return render_template("index.html", name=username)
# take query
# /views/profile?name=username
# http://127.0.0.1:8000/views/profile?name=username
@views.route("/profile")
def profile():
# return "hello testing"
# args=request.args
# name=args.get('name')
return render_template("track.html")
# return json to return json need dictionary
@views.route("/json")
def get_json():
return jsonify({'name': 'username', 'ID':123})
# redirect json
@views.route("/gotohome")
def gotohome():
return redirect(url_for("views.home"))
# ---------------
# stackify website
# IPStack key
# https://stackify.com/python-geocoder-a-guide-to-managing-locations-in-your-apps/
#----------------
#
import json
# json.loads(symbols)
key = "e88e972426c5be7ed2b8a1a45b4460dd"
@views.route('/track', methods=['POST',"GET"])
def my_form_post():
if request.method == "POST":
ip = request.form['text']
# processed_text = text.upper()
url = "http://api.ipstack.com/" + ip + "?access_key=" + key
r = requests.get(url)
print("r value", r.content)
longitude = r.json()["longitude"]
latitude = r.json()["latitude"]
contentt=r.json()
return render_template("trackpage.html",longitude =longitude ,latitude = latitude, contentt=contentt)
return render_template("form.html")
# login
# Route for handling the login page logic
@views.route('/login', methods=['GET', 'POST'])
def login():
error = None
if request.method == 'POST':
if request.form['username'] != 'admin' or request.form['password'] != 'admin':
error = 'Invalid Credentials. Please try again.'
else:
return redirect(url_for('home'))
return render_template('login.html', error=error)