Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #app.py
- from flask import Flask, render_template, jsonify
- app = Flask(__name__)
- @app.route('/index')
- @app.route('/')
- def index():
- data2=24
- # data1="""<html><a href='{{ url_for('/index_get_data') }}'>data2</a></html>"""
- # values = {"data": "this is page 1<br><a href='/index_get_data'>page 2</a>"}
- # return render_template('index.html',data=data1)
- # p=type(values)
- href = """<a onclick="showModal('event', 'url_for(product, data1)')" >+data2+</a>"""
- return render_template('index.html', data=href)
- @app.route('/product/<data1>')
- def stuff1(data1):
- host = 'localhost'
- user = 'root'
- password = ''
- db = 'mydata'
- try:
- con = pymysql.connect(host=host, user=user, password=password, db=db, use_unicode=True, charset='utf8')
- print('+=========================+')
- print('| CONNECTED TO DATABASE |')
- print('+=========================+')
- except Exception as e:
- sys.exit('error', e)
- cur = con.cursor()
- cur.execute("SELECT * FROM table1where productid=data1")
- data2 = cur.fetchall()
- return data2
- # index.html
- <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.18/css/jquery.dataTables.min.css"/>
- <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
- <script src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
- {% block body %}
- <div>{{data}}</div>
- {% endblock %}
- {% block javascript %}
- <script>
- function showModal(event, url) {
- if (typeof event.preventDefault !== "undefined") {
- event.preventDefault();
- }
- $.ajax({
- type: "POST",
- url: url,
- dataType: "html",
- success: function(data)
- {
- $('#drilldown-modal').find('.modal-body').html(data);
- }
- }
- );
- }
- $(document).on('click', function(e){
- showModal(e, (self).attr('href'));
- });
- </script>
- {% endblock %}
Add Comment
Please, Sign In to add comment