如何将我的python后端连接到我的HTML前端以创建用于Double hash的GUI?还有其他创建GUI的方法吗?

时间:2019-05-17 04:10:22

标签: python html

这是为我的迷你项目评估的。基本上,我需要一个GUI来显示双重哈希实现。我使用html和CSS创建了前端,但无法将后端连接到前端。

我已经用python和前端部分使用HTML和CSS编写了代码

html中需要嵌入我的python代码的双哈希页:

<html>
<head>
<link href='style1.css' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="icon" href="favicon.ico" type="image/x-icon">
<!--<script src="hash.js"></script>-->
<!-- method i tried to embed my code -->    
<!--<script type="text/javascript">
function runPyScript(input){
var jqXHR = $.ajax({
type: "POST",
url: "/double",
async: false,
data: { mydata: input }});
return jqXHR.responseText;}
$('#submitbutton').click(function(){
datatosend = 'this is my matrix';
result = runPyScript(datatosend);
console.log('Got back ' + result);
});
</script>-->
<!-- end of method -->  

<title>DOUBLE HASHING IMPLEMENETATION</title>
</head>
<br>
<br>
<body>
<h1> DOUBLE HASHING</h1>
<!--<h3 class="probingName">Type of Probing: </h3>-->
<div id="container">
<a href="fe.html"><i class="icon-home">Home</a></i><br>
</div>
<br>
<div id="instructions">
<p>Enter the size of the hash table:</p>
<form method="post">
<input type="text" name="size" placeholder="size" required>
<input class="btn btn-primary" type="submit" name="ENTER" value="ENTER">
</form>
</div> 

<div id="content">
<br />
<!-- my pyhton code -->     
<% def double_hashing(keys, hashtable_size, double_hash_value %>
<%hashtable_list = [None] * hashtable_size %>
<%for i in range(len(keys)): %>
<% hashkey = keys[i] % hashtable_size %>
<%if hashtable_list[hashkey] is None: %>
<% hashtable_list[hashkey] = keys[i] %>
<% else: %>
<% new_hashkey = hashkey%>
<%while hashtable_list[new_hashkey] is not None: %>
<%steps = double_hash_value - (keys[i] % double_hash_value) %>
<%new_hashkey = (new_hashkey + steps) % hashtable_size%>
<%hashtable_list[new_hashkey] = keys[i]%>
<%return hashtable_list %>


<% values = [26, 54, 94, 17, 31, 77, 44, 51] %>
<%=print(double_hashing(values, 21, 19))%>
<!-- end code -->
</div>
</html>

1 个答案:

答案 0 :(得分:0)

使用python软件包#include <bits/stdc++.h> using namespace std; #define lli long long int lli divide(lli n, lli dp[]) { lli ans = 0; if (n == 0) return 0; if (dp[n] != 0) return dp[n]; lli m1 = floor(divide(n / 2, dp)); lli m2 = floor(divide(n / 3, dp)); lli m3 = floor(divide(n / 4, dp)); lli sum = m1 + m2 + m3; ans = max(sum, n); dp[n] = ans; return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { lli n; cin >> n; lli dp[n + 1] = { 0 }; lli ans = divide(n, dp); cout << ans << endl; } } ,您可以仅用几行代码来设置具有HTML前端和python后端的Web服务器。

这是Flask网站:http://flask.pocoo.org/

这是一个Flask服务器的非常基本的示例,该服务器显示一个网页,您可以将数据发布到:

Flask

注意:要使from flask import Flask, render_template, request app = Flask(__name__) @app.route('/', methods=['GET']) def index(): return render_template('index.html') @app.route('/post', methods=['POST']) def post(): return "recived: {}".format(request.form) if __name__ == "__main__": app.run(debug=True) 正常工作,您的HTML文件必须位于名为render_template的文件夹中