简体   繁体   English

为什么我的 flask web 应用程序不能正常工作? 我自己找不到任何错误

[英]Why is my flask web app not working properly? I can't find any errors myself

So I tried to write my first flask web application and the website isn't working.所以我尝试编写我的第一个 flask web 应用程序,但该网站无法正常工作。 Here is my application.py.这是我的 application.py。 I have already tried to get the input.我已经尝试获取输入。 Is a second web page in case of error necessary?如果出现错误,是否需要第二个 web 页面? Because the website itself isn't running in my IDE and I can't make out any errors.因为网站本身没有在我的 IDE 中运行,所以我无法找出任何错误。

from flask import Flask, render_template, request
import requests
import json
from tempfile import mkdtemp
from flask_session import Session
import random

app = Flask(__name__)

app.config["SESSION_FILE_DIR"] = mkdtemp()
app.config["SESSION_PERMANENT"] = False
app.config["SESSION_TYPE"] = "filesystem"
Session(app)

# import permutation module
from itertools import permutations as prm

scrambled_word = list(str(raw_input("Input your jumbled word: ")))

# empty lists that will be appended to later
prm_list = []
possible_words = []

# take each permutation of the input and put in a list
for i in prm(scrambled_word):
  prm_list.append("".join(i))
  print i

def check(x, y):

   # open list of words
    dictionary = file('words.txt')

    # check each line in the dictionary against each item
    # in the list of permutations and add it to another empty list if it's a match
    for line in dictionary:
        for i in x:
            if i+'\n' == line:
                y.append(i)


check(prm_list, possible_words)

# delete duplicates
possible_words = list(set(possible_words))

# print out possible words
if len(possible_words) == 0 or len(possible_words) == 1 or len(possible_words) == 2 or len(possible_words) == 3:
    print "No match found"
else:
    for i in possible_words:
        print "Possible Word for Jumbled Word is: " + i


@app.route("/", methods=["GET", "POST"])
def index():
    # make sure that method is POST
    if request.method == "POST":
        app_id = 'fbea320c'
        app_key = '436eab6eae3dbeec6ec311328b9ff7dd'
        language = 'en'

    if request.form.get("Word")
        return render_template("final.html")

and here is my final.html这是我的决赛。html

<html lang="en">
<head>
  <style>
    input{
          max-width: 350px;
    }

    select{
       max-width: 400px;
    }

    #ABC {
        background-color: black;
        position: absolute;
        width: 95%;
      }

    #imh {
      width: 100%;
      height: 50%;
    }

    .centered {
      position: absolute;
      top: 25%;
      left: 50%;
      transform: translate(-50%, -50%);
      color: #ffffff;
      text-align: center;
    }
  </style>
  <title>Word Finder</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
  <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  </head>
  <body>
    <img src="/static/jumble.jpeg" id="imh">
    <div class="centered"><font size="7">Jumble Solver</font><font size="4"><p>Unscramble words!</p></font></div>
    <div class="container">
      <br><div class="row">
        <center><h1>Enter a Word</h1></center><br><br></div><div class="row">
        <div class="inpot"><center>
          <form method="post" action="/">
              <div class="form-group">
              {% if a == 0 %}
              <input type="text" name="Word" id="Word" autofocus autocomplete="off" class="form-control" placeholder="Enter a Word" onclick="return IsEmpty()" value="{{ j }}"></div>
              {% else %}
              <input type="text" name="Word" id="Word" autofocus autocomplete="off" class="form-control" placeholder="Enter a Word"/></div>
              {% endif %}
            <div class="form-group">
                     </div><input class="btn btn-danger" type="submit" name="submit" value="submit"></button>&nbsp;&nbsp;&nbsp;<input class="btn btn-danger" name="submit" value="next" type="submit"></button></form>
            <div class="row">
        <div class=" text-center">
          <h3>Search up any word!</h3>
          <p>With our jumble solver you can unscramble any mix of letters!</p>
        </div>
        <div class="col-sm-4 text-center">
        </div>
        <div class="col-sm-4 text-center">
                  </div></div>
    </div></div></font></body></html>

i'm pretty new to coding, and i can't figure out what's going wrong我对编码很陌生,我不知道出了什么问题

I have tried to run your code, so I made some modifications to make it run on my python 3.7 in the windows operating system.我试过运行你的代码,所以我做了一些修改,让它在我的 windows 操作系统上运行 python 3.7。 The following modifications and corrections:以下修改和更正:

1- use input instead of raw_input 1- 使用input而不是raw_input

2- use: 2- 使用:

    f = open("words.txt", "r")
    dictionary = f.readlines()

instead of file('words.txt')而不是file('words.txt')

3- and of course use print(something) instead of print something . 3-当然使用print(something)而不是print something

4- adding to the end of your code the run command: 4- 在代码末尾添加运行命令:

if __name__ == '__main__':
    app.run(host='0.0.0.0', debug=1)

5- Indentation in the function def check(x, y): should be corrected ` 5- function def check(x, y):应该更正`

6- Adding the missing : in if request.form.get("Word") 6- 添加缺失的:if request.form.get("Word")

Finally, the program runs, but you use input from console like raw_input or input , meanwhile, you run Flask web server, so you should use forms to get the user inputs.最后,程序运行,您使用来自控制台的输入,如raw_inputinput ,同时,您运行Flask web 服务器,因此您应该使用 forms 来获取用户输入。

It would be good if add a sample input data and some lines of the file words.txt如果添加示例输入数据和文件words.txt的一些行会很好

Good Luck:祝你好运:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么FLASK_APP无法找到我的工厂功能? - Why can't FLASK_APP find my factory function? 烧瓶重定向不起作用,但是我没有收到任何错误 - Flask redirect not working but I don't get any errors 为什么我的Flask应用程序中的图像无法正确显示? - Why can't my images in Flask application be properly displayed? 当我在heroku上重新部署我的flask应用程序时,为什么我最近的文章不能发表? - Why can't I keep my articles published recently when I redeploy my flask app on heroku? Can't add an item in a SQL database using SQLAlchemy for a Flask web app with Python. 如何继续获取有关它为什么不起作用的更多详细信息? - Can't add an item in a SQL database using SQLAlchemy for a Flask web app with Python. How do I proceed to get more details as to why it's not working? 为什么我不能更改运行 Flask 应用程序的主机和端口? - Why can't I change the host and port that my Flask app runs on? 为什么我在 localhost:5000 中看不到我的容器化 docker flask 应用程序? - Why Can't i see my containerized docker flask app in localhost:5000? 为什么在我的工作目录(Flask)中看不到创建的数据库文件? - Why can't I see the created database file in my working directory (Flask)? 为什么我不能使用 python smtplib 向自己发送邮件? - Why can't I send a mail to myself using python smtplib? 我无法在Flask应用中使用CSS设置背景 - I can't set the background using CSS in my Flask app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM