数独是一项快乐的益智游戏,起源于18世纪瑞士的一种数学游戏。解答者需要运用纸、笔进行演算,需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并满足每一行、每一列、每一个粗线宫(3*3)内的数字均含1-9,不重复。
本次分享讲展示如何利用Django来直观方便地破解数独。
首先新建两个模板来展示页面,一个是index.html,方便用户输入数独,此数独可以来自其他网站;一个是answer.html,用于展示用户输入的数独的答案。
index.html的代码如下:
<html> <head> {% load staticfiles %} <link rel=http://www.likecs.com/"stylesheet" type=http://www.likecs.com/"text/css" href=http://www.likecs.com/"{% static 'App/mystyle.css' %}" /> </head> <body background=http://www.likecs.com/"{% static 'App/mountain.jpg' %}"> <center><h1>Solve A Sudoku</h1></center> <form action=http://www.likecs.com/"/answer/" method=http://www.likecs.com/"get"> <table class=http://www.likecs.com/"sd" border=http://www.likecs.com/"0" align=http://www.likecs.com/"center" cellspacing=http://www.likecs.com/"1" cellpadding=http://www.likecs.com/"1"> <tr> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"1" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"2" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"3" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"4" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"5" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"6" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"7" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"8" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"9" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> <tr> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"10" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"11" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"12" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"13" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"14" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"15" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"16" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"17" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"18" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> <tr> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"19" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"20" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"21" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"22" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"23" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"24" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"25" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"26" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"27" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> <tr> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"28" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"29" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"topr"><input id=http://www.likecs.com/"30" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"31" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"32" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"topr"><input id=http://www.likecs.com/"33" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"34" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"35" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"36" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> <tr> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"37" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"38" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"39" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"40" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"41" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"42" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"43" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"44" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"45" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> <tr> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"46" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"47" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"48" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"49" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"50" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"51" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"52" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"53" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"54" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> <tr> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"55" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"56" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"topr"><input id=http://www.likecs.com/"57" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"58" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"59" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"topr"><input id=http://www.likecs.com/"60" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"61" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"52" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"top"><input id=http://www.likecs.com/"63" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> <tr> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"64" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"65" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"66" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"67" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"68" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"69" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"70" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"71" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"72" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> <tr> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"73" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"74" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"75" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"76" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"77" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"rr"><input id=http://www.likecs.com/"78" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"79" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"80" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> <td class=http://www.likecs.com/"xx"><input id=http://www.likecs.com/"81" class=http://www.likecs.com/"big" name=http://www.likecs.com/"grid" maxlength=http://www.likecs.com/"1"></td> </tr> </table> <br> <center> <button type=http://www.likecs.com/"reset" value=http://www.likecs.com/"Reset">Reset</button> <input type=http://www.likecs.com/"submit" value=http://www.likecs.com/"Show Anwser"> </center> </form> </body> </html>