Guest User

Untitled

a guest
Jan 13th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. #app.py
  2.  
  3. from flask import Flask, render_template, jsonify
  4.  
  5. app = Flask(__name__)
  6.  
  7.  
  8. @app.route('/index')
  9. @app.route('/')
  10. def index():
  11. data2=24
  12. # data1="""<html><a href='{{ url_for('/index_get_data') }}'>data2</a></html>"""
  13. # values = {"data": "this is page 1<br><a href='/index_get_data'>page 2</a>"}
  14. # return render_template('index.html',data=data1)
  15. # p=type(values)
  16. href = """<a onclick="showModal('event', 'url_for(product, data1)')" >+data2+</a>"""
  17. return render_template('index.html', data=href)
  18.  
  19.  
  20. @app.route('/product/<data1>')
  21. def stuff1(data1):
  22. host = 'localhost'
  23. user = 'root'
  24. password = ''
  25. db = 'mydata'
  26.  
  27. try:
  28. con = pymysql.connect(host=host, user=user, password=password, db=db, use_unicode=True, charset='utf8')
  29. print('+=========================+')
  30. print('| CONNECTED TO DATABASE |')
  31. print('+=========================+')
  32.  
  33. except Exception as e:
  34. sys.exit('error', e)
  35.  
  36. cur = con.cursor()
  37. cur.execute("SELECT * FROM table1where productid=data1")
  38. data2 = cur.fetchall()
  39. return data2
  40.  
  41. # index.html
  42.  
  43. <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.18/css/jquery.dataTables.min.css"/>
  44. <script src="https://code.jquery.com/jquery-3.3.1.js"></script>
  45. <script src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
  46.  
  47. {% block body %}
  48. <div>{{data}}</div>
  49. {% endblock %}
  50.  
  51. {% block javascript %}
  52. <script>
  53. function showModal(event, url) {
  54. if (typeof event.preventDefault !== "undefined") {
  55. event.preventDefault();
  56. }
  57. $.ajax({
  58. type: "POST",
  59. url: url,
  60. dataType: "html",
  61. success: function(data)
  62. {
  63. $('#drilldown-modal').find('.modal-body').html(data);
  64. }
  65. }
  66. );
  67. }
  68. $(document).on('click', function(e){
  69. showModal(e, (self).attr('href'));
  70. });
  71. </script>
  72. {% endblock %}
Add Comment
Please, Sign In to add comment